in reply to Extracting file name from path
Isn't a regexp going a little overboard for a pattern like this?
my $str = 'c:\dir\subdir\filename.ext'; my $filename = (split/\\/, $str)[-1];
Grabs everything after the last \ and I'm willing to bet much faster (and it's easier to read than that regexp). If I had retained more of the context talks in 'Camel' I seem to remeber you can drop the [-1] by getting it to still be in list context when assigned to $filename (instead of $filename getting the scalar 4) but I can't find the refference.
|
|---|