in reply to Strange Regex Behavior
It might be a little more obvious like this:
$b = 'test 100'; %hash = ( a => ($b =~ /(\d+)/ ? $1 : 0), b => ($b =~ /(\w+)/ ? 1 : 0), ); print "$hash{a}\n";
which prints
test
So, it did the second pattern match first, and interpreted $1 to be the result of that pattern match. It's the same sort of ambiguity that is found in, say, ($i++)+$i.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Strange Regex Behavior
by remiah (Hermit) on Dec 06, 2011 at 07:04 UTC | |
Re^2: Strange Regex Behavior
by BrowserUk (Patriarch) on Dec 06, 2011 at 06:57 UTC | |
by quester (Vicar) on Dec 06, 2011 at 07:12 UTC | |
by BrowserUk (Patriarch) on Dec 06, 2011 at 07:25 UTC | |
by quester (Vicar) on Dec 06, 2011 at 09:08 UTC |
In Section
Seekers of Perl Wisdom