Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Variable Declaration

by ikegami (Patriarch)
on Aug 31, 2007 at 15:09 UTC ( [id://636348]=note: print w/replies, xml ) Need Help??


in reply to Re: Variable Declaration
in thread Variable Declaration

The following would also work:

my $var2 = <cond1> ? a : y;

But be careful. Even slight complexity in its arguments can make it hard to read.

Replies are listed 'Best First'.
Re^3: Variable Declaration
by nobull (Friar) on Aug 31, 2007 at 16:11 UTC
    A third option is
    my $var2 = do { if ( <cond1> ) { a; } else { y; } };

    All three constructs are more-or-less interchangable and which one you use should be decided based on which is most readable in any particular instance.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://636348]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 09:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found