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
By rote learning.
Via Genetic memory.
It's provided by my firmware.
I just remember them.
Thirty days hath September
My computer gets it right, usually.
I just ask someone else.
Someone punches me on the first of the month.
Results (168 votes),