#!/usr/bin/perl use strict; use warnings; use File::Spec; { my $pathName = "/usr/tmp/booger/test.dat"; my $baseName = ExtractLastDir($pathName); print "Result is $baseName\n"; } exit; sub ExtractLastDir { my ($fullName, @extraStuff) = @_; if (!defined $fullName) { $fullName = ''; } my ($volumeName, $directoryPath, $fileName) = File::Spec->splitpat +h($fullName); my @directoryNames = File::Spec->splitdir($directoryPath); # Grab the last element from the directory -- but it is probably b +lank my $lastDirectory = pop @directoryNames; # So if it is blank, get the next one if ($lastDirectory eq '') { $lastDirectory = pop @directoryNames; } return $lastDirectory; } __END__ C:\Steve\Dev\PerlMonks\P-2013-10-30@1354-BaseDir>basedir3.pl Result is booger
In reply to Re^2: I humbly ask for your help with parsing
by marinersk
in thread I humbly ask for your help with parsing
by WxResearcher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |