in reply to Truncating Filename string
Here goes...
my $string = '/whatever/filepath/and/name.dat'; my $filename; if ( $string =~ m#/([^/]+)$# ) { $filename = $1; print $filename, "\n"; }
The regexp translated: Start by using 'm##' as the regexp delimiter instead of the more traditional m//, so that you don't have to escape the '/' character within the expresssion. Next, match the last '/' character in the string, then capture all of the rest of the characters that are not '/' through the end of the string.
This assumes that you're on an OS where path levels are delimited with '/'. You'll have to modify it if '\' is your delimiter of choice. This also assumes that there is at least one '/' in the path. ...so many assumptions, the module is probably a safer way of handling it.
Dave
|
|---|