more useful options | |
PerlMonks |
Re^3: Argument spamming terminalby hippo (Bishop) |
on Aug 20, 2021 at 08:42 UTC ( [id://11135981]=note: print w/replies, xml ) | Need Help?? |
I am glad that you are happy with the outcome. However, it would be remiss of me not to explain a little more about my example code as it seems that perhaps you have not fully grasped its meaning or method of construction. Firstly, the braces are important because they form a block which limits the scope of the warnings pragma. This is why in that example you see a warning when assigning to $foo (outside the block) but not to $bar (inside the block, with the scoped pragma). Secondly, the variables $bar, $bot and $foo are only present to illustrate the technique. So, if I were to amend your loop just to silence this one warning, I would do something more like this:
In this way the warning is only silenced when trying to call int (delete $rx->{"ping_$i"} || 0) and nothing else in the loop or enclosing subroutine. Finally, in silencing the warning you are potentially losing valuable information. Why are you trying to call int on a potentially non-numeric value in the first place? Would it not be better for your code to handle this eventuality properly? Writing robust code will save you time in the long run. Consider spending 5 minutes now to handle non-numeric values of $rx->{"ping_$i"} to save you hours of painful debugging later (especially because you have now silenced the warnings which might otherwise alert you to the problem). Caveat programmer. 🦛
In Section
Seekers of Perl Wisdom
|
|