in reply to Regexp context with ||
|| always imposes a scalar context on its left hand operand, which is also why you can't usefully say @a = @b || @c.
One way to work around that in this case is to use the ternary operator instead:
$a = ("ac" =~ /a(b)c/) ? $1 : 'd'; print $a;
Update: Another approach is to use an array dereference, which is a way of retaining the ||, though I think it is less clear:
Hugo$a = ("abc" =~ /a(b)c/)[0] || 'd'; print $a;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Regexp context with ||
by bsb (Priest) on Apr 09, 2003 at 02:30 UTC | |
|
Re: Re: Regexp context with ||
by JamesNewman (Initiate) on Apr 09, 2003 at 18:56 UTC |