morgon has asked for the wisdom of the Perl Monks concerning the following question:
could someone please explain this behaviour to me as it is unexpected for me:
In the first case I compile a regex immediately, in the second I define a string and only in the line where I match it get's compiled.my $regex1 = qr/(?:(?|(?:\")([^\\\"]*(?:\\.[^\\\"]*)*)(?:\")))/; my $regex2 = qq/(?:(?|(?:\")([^\\\"]*(?:\\.[^\\\"]*)*)(?:\")))/; my ($match1) = q|"hubba \"bubba\""| =~ $regex1; my ($match2) = q|"hubba \"bubba\""| =~ /$regex2/; print "$match1\n$match2\n"; __END__ output: hubba \"bubba\" hubba \
I would have expected that the result would be the same - but it isn't...
Why?
Many thanks!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: regex compilation
by davido (Cardinal) on Feb 12, 2019 at 17:57 UTC | |
by AnomalousMonk (Archbishop) on Feb 12, 2019 at 20:29 UTC | |
by morgon (Priest) on Feb 12, 2019 at 18:05 UTC | |
by AnomalousMonk (Archbishop) on Feb 12, 2019 at 18:31 UTC | |
by Laurent_R (Canon) on Feb 12, 2019 at 18:51 UTC | |
Re: regex compilation
by Corion (Patriarch) on Feb 12, 2019 at 17:37 UTC | |
by morgon (Priest) on Feb 12, 2019 at 17:43 UTC | |
by haukex (Archbishop) on Feb 12, 2019 at 18:12 UTC | |
by AnomalousMonk (Archbishop) on Feb 12, 2019 at 18:25 UTC |