in reply to Putting the stringified Regexp object into code
Do you really need to stringize the entire if-statement? If you can get away with it, it's much simpler to use the stringized regex object on its own. (When a match such as m// or s/// is compiled, the compiler looks for terminating delimiters before interpolating scalars, so embedded '/' characters in the scalars should not be a problem.) (Also: The =~ operator will bind to a plain old string.)
>perl -wMstrict -le "my $rx = qr{ foo/bar }xms; print 'ref: ', ref $rx; $rx = qq{$rx}; print 'de-refized: ', ref $rx; print $rx; ;; my $str = 'xx foo/bar yy'; print 'match' if $str =~ $rx; print qq{captured '$1'} if $str =~ m/($rx)/; " ref: Regexp de-refized: (?^msx: foo/bar ) match captured 'foo/bar'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Putting the stringified Regexp object into code
by sedusedan (Monk) on Nov 06, 2012 at 19:11 UTC | |
by roboticus (Chancellor) on Nov 06, 2012 at 20:44 UTC | |
by sedusedan (Monk) on Nov 07, 2012 at 00:11 UTC |
In Section
Seekers of Perl Wisdom