Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: sum of integers in a column

by mjscott2702 (Pilgrim)
on Oct 12, 2010 at 12:36 UTC ( [id://864843]=note: print w/replies, xml ) Need Help??


in reply to Re: sum of integers in a column
in thread sum of integers in a column

Shouldn't that be:  $sum[$_] += $column[$_] for 0..$#column;

I presume the $i should actually be the default index variable $_ generated by the for loop?

Replies are listed 'Best First'.
Re^3: sum of integers in a column
by muba (Priest) on Oct 12, 2010 at 12:41 UTC

    You're quite right. Initially I wrote it with a for my $i (...) {...} loop but then thought I could do it with a postfix for. Forgot to replace that one instance of $i with $_. Corrected. Thank you :)

      Luckily using strict and warnings would have highlighted the typo :)
      - - for failure to add the pragmas you advocated -- which would have shown you that your correction is still incorrect.

Log In?
Username:
Password:

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

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

    No recent polls found