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. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order. -- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>