in reply to Syntax for 1 line "either this or this"

A related operator idiom for assuming a default value:
$myVar = $somevalue || 'default';

Technically, it's not quite the same as the previous statements, but I'd say it is more commonly used than the trinary form.

There's whether something exists, whether it is defined (has a value different from undef), whether it has a "true" value (anything but undef or '' or 0 or '0'), and whether it's a reference or a non-referential scalar.

--
[ e d @ h a l l e y . c c ]

Replies are listed 'Best First'.
Re: Re: Syntax for 1 line "either this or this"
by parv (Parson) on May 30, 2003 at 06:54 UTC

    Above example ought to be qualified w/ a statement similar to "To set a default value if $somevalue is false, use this ...".

    I discovered that i need to set default iff a given value is undefined, not false. Thankfully, perl 6 will make it to take care of that just as easily -- search for "It's a setup" -- as the above example w/ help of // operator.

    Change, May 30 2003: Removed "binary" from the last sentence describing the behaviour of //. The operator is listed being binary in the referenced portion ("It's a setup") of Exegesis 3, but as an unary operator at the end of the article.