Re: Shortening the ?: construct



On Fri, 17 Apr 2009 22:02:37 -0500, Chap Harrison wrote:

my $foo = ( defined $very_long_expression ? $very_long_expression :
"n/a" );
[...]

At some point I thought I read about a shorter way to write this, that
did not involve repeating the $very_long_expression in the same
statement. Perhaps a special variable or something, acting sort of like
a pronoun. Anyone know of a shortcut?

Thanks,
Chap Harrison
Perl 5.8.8

Well, if you're able to upgrade to 5.10:

my $foo = $very_long_expression // "n/a";

--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
http://www.informit.com/store/product.aspx?isbn=0137001274
.



Relevant Pages

  • Re: How to remove hidden directories
    ... Repeating these commands: ... If anyone can point me to a shorter or more efficient method please ... How do I get rid of this rubbish? ...
    (microsoft.public.windows.vista.general)
  • Re: xpP slow after 2003 Server upgrade
    ... You keep repeating this "fact" - where may we find some proof? ... Before the upgrade mine was up in about 20 seconds max ... It is NOTORIOUSLY slow left on ... > about 2 seconds to get on to the network. ...
    (microsoft.public.windowsxp.network_web)