in reply to Assign Contains RegEx WTF??

This snippet does the following:
  1. Copies the contents of $fname to $bname
  2. Binds the regular expression to $bname
  3. Removes everything up to the final backslash ( \ ) from the string stored in $bname. Specifically, this expression (using the alternate delimiter '#') greedily matches any number of any characters (.*) followed by a backslash (which must be escaped, thus \\).

So the string 'C:\folder\file' would be transformed to 'file'.

All the details needed to parse the regular expression can be found in perlre and/or prelretut.

Replies are listed 'Best First'.
Re^2: Assign Contains RegEx WTF??
by Anonymous Monk on May 20, 2009 at 14:22 UTC
    Thank you wise monk(s)! My confusion has blossomed into amusement. The original "programmer" was only good at "pasting".

    Original code:
    $fname = $TMP_DIR . "\\" . $tnum . ".tmp"; ($bname = $fname) =~ s#.*\\##s;
    New code: (terseness removed)
    $bname = $tnum . ".tmp"; $fname = $TMP_DIR . "\\" . $bname;
      If you are just modifying paths, you may consider using the File::Spec module. May very well be overkill for your app, though.