On 10/2/06, Mumia W. <[EMAIL PROTECTED]> wrote:
On 10/02/2006 01:54 PM, Rob Dixon wrote: > Bryan R Harris wrote: >> >> ************************************** >> $ptypeline = "# movable ortProj ortho 0.000 0.000"; >> >> ($ptype) = ($ptypeline =~ /movable.+(sine|geo|radial|ortho)/i) || >> "(missing)"; >> >> print $ptype, "\n"; >> ************************************** >> >> >> The above code prints "1", where I want it to print "ortho". Is that >> possible? >> >> (Preferably in one line, since I'm a *big* fan of perl golf. =) > > $ptype = $ptypeline =~ /movable.+(sine|geo|radial|ortho)/i ? $1 : > "(missing)"; > > Rob > 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? - Jen