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
shiny regexes and rules offered by Perl 6
other CPAN module
by looking at it on my monitor
I print it and I read it in spare time
first I convert it into $FORMAT, then I parse it
I hire someone to do it
using my custom module
I write a brand new language to do the task
on the server where I play as human, XML is forbidden
what is XML?
I speak XML natively
I write a new grammar for Perl 6
some other way
Results (398 votes),