> Jen Spinney wrote:
>> On 10/2/06, Mumia W. <[EMAIL PROTECTED]> wrote:
>>> 
>>> Yes, and here is another way:
>>> 
>>> $ptype = (($ptypeline =~ /movable.+(sine|geo|radial|ortho)/i)[0]) ||
>>> '(missing)';
>> 
>> How does that way work?  I was curious, so I tested it myself and it
>> clearly did work, but I have no idea why.  Shouldn't the || operator
>> turn the entire right side into a condional expression that evaluates
>> to either 1 or 0?
> 
> In scalar context the expression:
> 
> $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i
> 
> returns "true" or "false" (1 or '') and in list context it returns the
> contents of any capturing parentheses in the pattern.
> 
> The expression:
> 
> ( $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i )[ 0 ]
> 
> is a list slice so the regular expression is in list context but the slice is
> a single value so the expression is a scalar.
> 
> The || operator will only work with scalar values, not with lists, so this
> works because the list has been converted to a scalar with the list slice.


Thanks, John, Rob, and Mumia.  Rob's answer was fast and got me going,
Mumia's answer was more elegant (in my opinion), and John's answer helped me
understand why my code didn't work.

Much appreciated!

- Bryan

 



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to