in reply to $_ works, $my_variable doesn't?
You seem to be misunderstanding how && works in this case. When you say:
$_ =~ /a/i && /e/i && /i/i && /o/i && /u/ithat essentially gets extrapolated to:
($_ =~ /a/i) && ($_ =~ /e/i) && ($_ =~ /i/i) && ($_ =~ /o/i) && ($_ =~ /u/i)Then when you write:
$one_line =~ /a/i && /e/i && /i/i && /o/i && /u/iit similarly gets extrapolated to:
($one_line =~ /a/i) && ($_ =~ /e/i) && ($_ =~ /i/i) && ($_ =~ /o/i) && ($_ =~ /u/i)Notice how all the subsequent matches look in $_? The only reason your first example works is because the match operator defaults to matching against $_. The solution is either to bind each and every match to the variable you want to match, or to combine all the regexes into one, like so: $one_line =~ /a|e|i|o|u/i.
Update: replies pointed out that my combined regex was not the same as the original intent.
Update: I've posted a single-regex solution deeper in the thread. It may have problems that I'm not aware of, but seems to test out OK.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: $_ works, $my_variable doesn't?
by dragonchild (Archbishop) on Mar 30, 2004 at 02:09 UTC | |
by bageler (Hermit) on Mar 30, 2004 at 03:54 UTC | |
by dragonchild (Archbishop) on Mar 30, 2004 at 13:53 UTC | |
by duff (Parson) on Mar 30, 2004 at 14:28 UTC | |
by dragonchild (Archbishop) on Mar 30, 2004 at 14:33 UTC | |
|