Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Argument spamming terminal

by hippo (Bishop)
on Aug 20, 2021 at 08:42 UTC ( [id://11135981]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Argument spamming terminal
in thread Argument spamming terminal

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:

# first process all available player entries for (my $i = 0; exists $rx->{"player_$i"}; $i++) { # add player info to UPI and remove from hash my @player; push @player, $sid; push @player, delete $rx->{"player_$i"} || "Derp"; push @player, delete $rx->{"team_$i"}; push @player, int (delete $rx->{"frags_$i"} || 0); push @player, delete $rx->{"mesh_$i"}; push @player, delete $rx->{"skin_$i"}; push @player, delete $rx->{"face_$i"}; { # You should put a comment here to say why you are muting these +warnings. no warnings 'numeric'; push @player, int (delete $rx->{"ping_$i"} || 0); } push @player, delete $rx->{"ngsecret_$i"}; push @upi, \@player; }

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.


🦛

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11135981]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-20 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found