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 (Archbishop) 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 '..'; }

    🦛