in reply to Re: Dynamic Regex?
in thread Dynamic Regex?
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Dynamic Regex?
by tachyon (Chancellor) on May 21, 2001 at 05:06 UTC |