Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: using an array in a while loop

by choroba (Archbishop)
on Jan 31, 2022 at 09:47 UTC ( #11140990=note: print w/replies, xml ) Need Help??


in reply to using an array in a while loop

Normally, you shouldn't need the number at all:
my @dirs = ('/path/to/dir1', '/some/other/path/to/dir2', '/dir3'); for my $dir (@dirs) { ... }

To populate the array with the names, you can use a map:

my @dirs = map { sprintf 'abc_%03d', $_ } 1 .. 100;

If you really need the array index, loop over the indices rather than the elements themselves:

for my $i (0 .. $#dirs) { my $dir = $dirs[$i]; ... }

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2022-09-25 20:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer my indexes to start at:




    Results (116 votes). Check out past polls.

    Notices?