Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: how does perl handle variables

by marto (Bishop)
on May 17, 2013 at 11:41 UTC ( #1033964=note: print w/ replies, xml ) Need Help??


in reply to how does perl handle variables

"in this case it should ideally throw some error but it just considers > a,b,c... as 0 ? why does it do that"

Adding use strict; use warnings; is advisable. See strict, warnings:

#!/usr/bin/perl use strict; use warnings; my @a=qw( 1 2 3 4 a b c g f); my $s=0; foreach my $i(@a){ $s+= $i; print "i: $i - s: $s\n"; } print $s;

shows:

D:\>perl derp.pl i: 1 - s: 1 i: 2 - s: 3 i: 3 - s: 6 i: 4 - s: 10 Argument "a" isn't numeric in addition (+) at derp.pl line 10. i: a - s: 10 Argument "b" isn't numeric in addition (+) at derp.pl line 10. i: b - s: 10 Argument "c" isn't numeric in addition (+) at derp.pl line 10. i: c - s: 10 Argument "g" isn't numeric in addition (+) at derp.pl line 10. i: g - s: 10 Argument "f" isn't numeric in addition (+) at derp.pl line 10. i: f - s: 10 10


Comment on Re: how does perl handle variables
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (17)
As of 2015-07-07 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (89 votes), past polls