Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: ${^MATCH} sometimes fails in target of substitution?

by farang (Hermit)
on Jun 16, 2013 at 18:10 UTC ( #1039236=note: print w/ replies, xml ) Need Help??


in reply to ${^MATCH} sometimes fails in target of substitution?

I think this has to do with optimization of the regexp. I may not be using terminology quite right, but Perl sees that the $sub variable can be interpolated, so the regexp is eval'd at compile time, thereby populating ${^MATCH}. That is, it is only after being eval'd once that ${^MATCH} gets the value from the search.

The following code also forces a similar 'second eval'.

my $x = "abcde"; $x =~ s/b../sprintf "==${^MATCH}=="/pe; print "$x\n";


Comment on Re: ${^MATCH} sometimes fails in target of substitution?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (12)
As of 2014-08-20 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (108 votes), past polls