Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Assign Contains RegEx WTF??

by kennethk (Abbot)
on May 19, 2009 at 15:09 UTC ( [id://764937]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://764937]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2024-04-25 19:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found