Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: using an array in a while loop

by choroba (Cardinal)
on Jan 31, 2022 at 09:47 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-28 16:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found