Q&A > strings > How do I extract a file name from a path string contributed by amasidlover
( $dir, $file ) = m/(.*)[\\\/](.+)/ ? ( $1, $2 ) : ( undef, $_ );
I'm not sure why I would want to use that code fragment and not File::Spec::Functions.
Alex / talexb / Toronto
"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds
I wholeheartedly agree:
my $fname = '/home/legato/filename.pl';
my ($vol, $path, $filename) = splitpath($fname);
# $filename now contains 'filename.pl'
Anima Legato.oO all things connect through the motion of the mind
A foolish day
Just another day
Internet cleaning day
The real first day of Spring
The real first day of Autumn
Wait a second, ... is this poll a joke?
Results (441 votes),