Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Argument spamming terminal

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


in reply to Argument spamming terminal

Is there a way to tell perl to ignore that error?

It isn't an error, it's a warning. As such you can mute it in the tightest possible scope.

#!/usr/bin/env perl use strict; use warnings; my $bot = 'foo'; # This will warn my $foo = int $bot; # This will not { no warnings 'numeric'; my $bar = int $bot; }

perldoc warnings for more.


🦛

Replies are listed 'Best First'.
Re^2: Argument spamming terminal
by CougarXR7 (Acolyte) on Aug 19, 2021 at 22:09 UTC

    Thank you! For correcting me about it being a warning not an error! Using your code stopped the spamming yet it still shows a few line in terminal. Still way much better!

Re^2: Argument spamming terminal
by CougarXR7 (Acolyte) on Aug 20, 2021 at 03:28 UTC

    Using your code I figured out how to stop the warning!

    sub unify_information { my ($sid, $rx) = @_; my %uei; # unified extended info my @upi; # unified player info my $bot = 'foo'; # FIXME unify with {player playername name, other keys/columns} # This will not # 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"}; no warnings 'numeric'; my $bar = int $bot; push @player, int (delete $rx->{"ping_$i"} || 0); no warnings 'numeric'; #my $bar = int $bot; push @player, delete $rx->{"ngsecret_$i"}; push @upi, \@player; } # return remaining values, player array return ($rx, \@upi); } 1;

    By placing your code around the line causing the warning like I did, it stopped printing the warning! Thank You!

      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://11135968]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found