($totcalls += $layer3) =~ s/^[\s+]([0-9]) Active.*/$1/;
I think you're confused with your order of operations ... you code will do the addition first, then the substitution (which fails, because it's operating on an integer)
ccn's solution will get rid of the warning by fixing the addition, but there's then no reason to do the substitution. I'm guessing you were probably trying to do:
$totcalls += [ $layer3 =~ m/^\s*([0-9]+) Active/ ]->[0];... which has the advantage that it'll throw some warnings when there's bad values in $layer3:
use strict; use warnings; my $totcalls = 0; my @data = ( '2 Active Layer 3 Call(s)',' 4 Active', '12 Active', 'bla +h', undef, '' ); foreach my $layer3 (@data) { print "INPUT : $layer3 \n"; $totcalls += [ $layer3 =~ m/^\s*([0-9]+) Active/ ]->[0]; print "TOTAL : $totcalls \n"; }
In reply to Re: avoid warnings in Copying and Substituting Simultaneously
by jhourcle
in thread avoid warnings in Copying and Substituting Simultaneously
by mvcorrea
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |