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'
In reply to Re: Putting the stringified Regexp object into code
by AnomalousMonk
in thread Putting the stringified Regexp object into code
by sedusedan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |