if ($Path =~ m{^(.*)\/([^\/]*)}) # if whatever-is-in-$Path matches that pattern, # which should imho better be written as # m{^(?:([^/]*/)+([^/]*)} { # then $Dir is "the whole thing before the last slash" # when you use my pattern, you'll have to chop() it $Dir = $1; # $File is averething after the last slash $File = $2; # $Ext will always be undef $Ext=$3; } else { # otherwise the $File is the whole $Path $File = $Path; } # next part if ($File =~ m{^(.*)\.([^\.]*)}) # again "death to dot star": # m{^([^.]*.)+([^.]*)} { # if that one matches, $File is everythin before the # last dot # $Dot becomes '.' # $Ext is everything after the last period $File = $1; $Dot = "."; $Ext = $2; } else { # otherwise $Dot and $Ext are empty strings $Dot = ""; $Ext = ""; } # next part if (-d "/$Dir/$File") # if "whetever results when you join $dir and $file with # a slash and preceed it by another slash" truns out to be # resolved as directory { # then $File, preceeded by slash, is appended to $Dir $Dir .= "/$File"; # and $File becomes an empty string $File = ""; }

All in all this is rather ugly, although not yet insecure, which depends on what happens next...

--
http://fruiture.de

In reply to Re: Perl string matching by fruiture
in thread Perl string matching by wizard341

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.