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

 $myvar = !defined $somevalue ? "default" : $somevalue;

or better yet

 $myvar = defined $somevalue ? $somevalue : "default";


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller


Replies are listed 'Best First'.
Re: Re: Syntax for 1 line "either this or this"
by theAcolyte (Pilgrim) on May 29, 2003 at 23:09 UTC
    This looks like exactly what I remembered. Thanks so much. If it's not too imposing, however, could you explain why/how this works? OTOH, I may be able to find info on "?" and ":" as operators in Programming Perl. :-)
      You will find information about it in the Camel book... the "?" and ":" comprise a single operator called the "ternary" or "trinary" operator, so look for that in the index. You can also find information about it in perlop. Search for "Ternary".

      -- Mike

      --
      just,my${.02}

      Programming Perl 3rd Ed. Section 3.16 Conditional operator.

      Or perlsyn Conditional operator.


      Examine what is said, not who speaks.
      "Efficiency is intelligent laziness." -David Dunham
      "When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller