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 = "path1path2path3 ile.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 = "path1path2path3 ile.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.

In reply to Extracting filename from a path string by Snaps_Provolone

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.