PDA

View Full Version : Opening up a directory with a variable number


perlhelp
08-01-2007, 08:51 PM
Hi everyone,
I am relatively new to perl. I am trying to write a script that can access directories that have variable numbers appended to the end. For example, I have 4 directories that all have an incremental number (1->4) and then an incremental number at the end (x->x+4) that is variable. Besides that the names are identical. For example:

this_is_identical_1_more_identical_15
this_is_identical_2_more_identical_16
this_is_identical_3_more_identical_17
this_is_identical_4_more_identical_18

The 1->4 part I put in the for loop. However, how do I access the directory with an unknown number at the end? I am running this on a unix server, so it might be easiest to use the 'tab' button to autocomplete if that is in any way possible. Any ideas on how to enter these directories?
Thanks!
Marc

KevinADC
08-01-2007, 10:07 PM
as suggested on the other forum:

for (1..4) {
$n = $_;
$r = $n+4;
my $dir = "SS_${n}_MAX_1$r";
print "$dir\n";
chdir "SS_${n}_MAX_$r";
}

nkrgupta
08-02-2007, 08:42 AM
...... I am running this on a unix server, so it might be easiest to use the 'tab' button to autocomplete if that is in any way possible. .......

I guess that's what we call "Out of the Box" thinking!! :eek:

s_pradeep
08-02-2007, 09:06 AM
LOL! That's indeed an easy solution!