[Perl] Determine directory name

Hi there,

I wonder if it is possible the determine a name of a directory which is different on various hosts.

Let me try to explain.

I have the directory /tmp/dir1/dir2/canchangedir.
This directory name is different on various hosts.
I need to use the directory name, independent from the host I am on.

This is the directory structure on all hosts (example):

/tmp/dir1
/tmp/dir1/dir2
/tmp/dir1/dir2/canchangedir
/tmp/dir1/dir2/canchangedir/dir3
/tmp/dir1/dir2/file1
/tmp/dir1/dir2/file2
/tmp/dir1/dir2/file3

The name "canchangedir" is different on all hosts.
The structure is the same and the dir1 and dir2 name too.

I tried with find and basename, but did not succeed.

Anyone out there that can do the magic ??

Thanks,

E.J.

open the tmp directory and search it?

@KevinADC,

Okay, a bit short (open it ? search it ? search what ?) , but I think I got it.

@dir2_contents = </tmp/dir1/dir2/*>;

foreach $item (@dir2_contents) {
  if ( -d $item ) {
    $needed_dir = basename($item);
  }
}

printf "needed_dir = $needed_dir\n";