in reply to Re: How would you shorten this regexp conditional?
in thread How would you shorten this regexp conditional?
Beware.. I've been burned by code like that. In a list context (which the indicies of a suffix part is eval'ed in), that's an empty list return for false, not "0", so you end up with an empty list value, and $color is undef, not the first item! You need a scalar inside the brackets to get it right, as in:my $color = ('b','w')[$white =~ /princepawn/];
my $color = ('b','w')[scalar $white =~ /princepawn/];
-- Randal L. Schwartz, Perl hacker
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: How would you shorten this regexp conditional?
by japhy (Canon) on Jan 25, 2002 at 19:07 UTC | |
by merlyn (Sage) on Jan 25, 2002 at 19:10 UTC |