Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Answer: How to deal with undefined returned variables.

by Russ (Deacon)
on Mar 05, 2002 at 19:51 UTC ( #149483=categorized answer: print w/replies, xml ) Need Help??

Q&A > subroutines > How to deal with undefined returned variables. - Answer contributed by Russ

knight makes a good point. Fortunately, in Perl 6, there will be a defaulting operator to simplify this very problem.
A binary // operator is the defaulting operator.
That is:
$a // $b
is short for:
defined($a) ?? $a :: $b
except that the left side is evaluated only once. It will work on arrays and hashes as well as scalars. It also has a corresponding assignment operator, which only does the assignment if the left side is undefined:
$pi //= 3;
Perl 6 should be such fun!

Replies are listed 'Best First'.
Re: Answer: How to deal with undefined returned variables.
by rinceWind (Monsignor) on Mar 06, 2002 at 17:00 UTC
    I take it that the difference between // and || is the difference between testing truthfulness and testing definedness.

    Hence there is not difference between $a // $b and $a || $b unless $a is 0 or "".

    It doesn't sound that useful to me.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
[ambrus]: My boss wants to generate output data that is impossible to compute from the inputs we have. And I'm trying to convince him that he shouldn't do that.

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-12-12 12:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (332 votes). Check out past polls.

    Notices?