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
Frying pan on the stove
Results (336 votes). Check out past polls.