Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: using an array in a while loop

by Anonymous Monk
on Jan 31, 2022 at 16:38 UTC ( [id://11140996]=note: print w/replies, xml ) Need Help??


in reply to using an array in a while loop

Because this is Perl, There Is More Than One Way To Do It. Here is an array-less solution given your statement about how the folders are named:

for ( my $i = 1; $i <= 4; $i++ ) {
    my $dir_name = sprintf 'abc_%03d', $i;
    chdir $dir_name or die "Unable to change to $dir_name: $!";
    ...
    chdir '..';
}

But in real life I would probably use File::Find like everyone else.

Replies are listed 'Best First'.
Re^2: using an array in a while loop
by hippo (Bishop) on Jan 31, 2022 at 16:48 UTC

    A perlish equivalent:

    for my $i ('001' .. '004') { my $dir_name = "abc_$i"; chdir $dir_name or die "Unable to change to $dir_name: $!"; ... chdir '..'; }

    🦛

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-25 09:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found