Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Foreach Loops

by sh1tn (Priest)
on Mar 15, 2005 at 19:26 UTC ( #439727=note: print w/ replies, xml ) Need Help??

in reply to Foreach Loops

Not so clean:

for(0..@arr){ $arr[$_] }
for(1..@arr){ print $arr[--$_], $_, $/ } # diff ?

Comment on Re: Foreach Loops
Select or Download Code
Replies are listed 'Best First'.
Re^2: Foreach Loops
by samtregar (Abbot) on Mar 15, 2005 at 19:42 UTC
    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:


      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.


Log In?

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-09-01 04:48 GMT
Find Nodes?
    Voting Booth?

    The oldest computer book still on my shelves (or on my digital media) is ...

    Results (367 votes), past polls