Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^6: Using an array element as a loop iterator

by LanX (Canon)
on Nov 08, 2013 at 19:45 UTC ( #1061748=note: print w/ replies, xml ) Need Help??


in reply to Re^5: Using an array element as a loop iterator
in thread Using an array element as a loop iterator

> but that's kind of ugly.

maybe easier written with while loops?

 while ($a[0] =shift @a1) { ... }

... well at least for me better readable :)

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re^6: Using an array element as a loop iterator
Download Code
Re^7: Using an array element as a loop iterator
by Eily (Chaplain) on Nov 08, 2013 at 20:14 UTC

    It surely is ^^. The problem is that you can't use that construct like this: while( $a[0] = shift `cat file` ) (but that is a unusual way to read a file, indeed). So you do have to set @a1 first, which is the first part of my for loop. And if @a1 contains a value that is false, $a[0] = shift @a1 will be false as well, so the loop will stop early. defined($a[0] = shit @a1) would work, unless you want to use undef as a value. That's why I used @a1 in scalar context as the third part of the for loop.

      agreed! ++ =)

      Cheers Rolf

      ( addicted to the Perl Programming Language)

Re^7: Using an array element as a loop iterator
by gurpreetsingh13 (Scribe) on Nov 09, 2013 at 08:59 UTC
    Thanks a lot. Got the point.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2014-10-24 23:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (138 votes), past polls