Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Parens mess up regex substitute

by Crackers2 (Vicar)
on Jan 26, 2012 at 16:14 UTC ( #950154=note: print w/ replies, xml ) Need Help??


in reply to Parens mess up regex substitute

While all of the above answers are correct, I think they may be slightly missing the point of your question. What I understand you're asking is: "Why do the parens in $str do not screw up

(my $name = $str) =~ s{.*/}{}; # basename

but do screw up

(my $path = $str) =~ s{$name}{};

?"

And the answer to that is: they don't. It's not the parens in $str that are the problem in the second substitution, it's the parens in $name


Comment on Re: Parens mess up regex substitute
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2014-12-25 12:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls