On Mon, 05 Mar 2001 10:33:05 +0100, Giorgio Valoti wrote:
>Hi all,
>perhaps it's a silly question but what I'd like to do is something like:
>
>#
>#pseudocode
>#
>my $switch = 'i';
>if ($something =~ m/regex/$switch) {
>...
>}
>
>I tried with eval and double quoting interpolation with no luck. Is
>something like this possible?
In later perls, you can incorporate the switch inside the regex:
/(?i:regex)/
and there you'd be free to replace the "i" with a variable.
In 5.6.0:
$_ = 'Yet Another Perl Hacker';
$switch = 'i';
print /(?$switch:PERL)/?'Y':'N';
-->
Y
But, it doesn't work in 5.004/MacPerl.
eval() should still work.
eval("\$something =~ m/regex/$switch")
--
Bart.