I have a directory path:
my $temp = "/a/b/c/d";
my $upDirectory = dirname( $temp );
This returns “/a/b/c”.
But I need just “c”. I have to compare it with a string to determine if it is the right directory.
Is there a way other than split on “/”? I do not want to use this. The Perl code has to be used on multiple platforms.
Can splitdir help?
There are, of course, many ways to do it but if your main concern is portability to other platforms then File::Spec is probably a reasonable bet. Look for
splitpathandsplitdir.