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
DejaVu Sans Mono
Droid Sans Mono
Envy Code R
Source Code Pro
The default, whatever it is
Results (353 votes). Check out past polls.