Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Foreach Loops

by samtregar (Abbot)
on Mar 15, 2005 at 19:42 UTC ( [id://439736]=note: print w/replies, xml ) Need Help??


in reply to Re: Foreach Loops
in thread Foreach Loops

And not so right. You're off by one!

$ perl -e '@a = (1, 2, 3); for (0..@a) { print "A$_: $a[$_]\n" }' A0: 1 A1: 2 A2: 3 A3:

-sam

Replies are listed 'Best First'.
Re^3: Foreach Loops
by sh1tn (Priest) on Mar 15, 2005 at 20:00 UTC
    That's why I said "Not so clear":
    for(1..@arr){ print $arr[--$_], $_, $/ }


      Actually you said "not so clean" not "not so clear" and your code didn't start from 1.

      -sam

        My mistake - forgotten s/.$/n/ after "not so clear"


Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-25 20:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found