Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: how does perl handle variables

by marto (Chancellor)
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 making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2014-10-01 01:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (386 votes), past polls