I am trying to work with CGI.pm to support file uploads. When the form is submited the filename includes the path from the client. I need to strip this extra path off the filename before I can open and write the file locally. I have tried a few things and the results were odd. Any ideas?
$path = "\path1\path2\path3\file.ext";
$path =~ s/(.*)\\(.*)/$2/gi;
print "$path";
Result = "path1path2path3ile.ext"
Note: The wierd character after 3 looks like a little circle on top of a cross in my command prompt window on NT.
use File::Spec;
$path = "\path1\path2\path3\file.ext";
($volume,$directories,$file) = File::Spec->splitpath($path);
print "$file";
Result = "path1path2path3ile.ext"
Note: Again there is the little funky character.
Now for the kicker -
$path = "`path1`path2`path3`file.ext";
$path =~ s/(.*)`(.*)/$2/gi;
print "$path";
Result - "file.ext" Now thats what I am after hehe. I don't know why but for some reason the \ character seems to be causing me some troubles. I even tried using \\ and \x5C I don't know what else to try. I have read everything I can find on this suject, and have tried everything, but all seem to fail with this path.