The second does not work either. It is equivalent to:Passing $pat into a sub is no problem using either of the second two methods above. The first does not work period as you will see if you run it.$pat = "m/foo/"; print "foo1\n" if "foo" =~ $pat; $pat = m/foo/; print "foo2\n" if "foo" =~ $pat; $pat = qr/foo/; print "foo3\n" if "foo" =~ m/$pat/;
$pat will be either 1 or the null string, depending on whether $_ matches /foo/. You will see this if you run it and actually examine the value of $pat.$pat = ($_ =~ m/foo/); print "foo2\n" if "foo" =~ $pat;
In reply to Re: Re: Dynamic Regex?
by chipmunk
in thread Dynamic Regex?
by footpad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |