A quick and dirty solution might be really to use something like
my @path = split m:/:, "/home/temp/login";
Disadvantage of such a solution is that your code will break if a dirname contains a slash or you start working on Windows.
If you really only want the relative dirnames, the following snippet will print them:
use File::Basename;
my $d = "/home/temp/login";
my @b = ();
while ($d ne dirname($d)) { # as long as we can move up directory t
+ree, when we are at root the dirname won't change any more
push @b, basename($d);
$d = dirname($d)
}
print join "\n", reverse(@b)
Greetings,
Janek Schleicher
Update: Fixed a typo in script.