Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re^3: Sequential defined-or operators

by ikegami (Pope)
on Jan 14, 2008 at 12:18 UTC ( #662281=note: print w/replies, xml ) Need Help??

in reply to Re^2: Sequential defined-or operators
in thread Sequential defined-or operators

Just be careful with precedence. Absent prototypes overriding the default,

my $value = $hash{$arg} // func $arg // 'default';
my $value = $hash{$arg} // func($arg // 'default');

Putting parens around the low precedence bit solves the problem.

my $value = $hash{$arg} // (func $arg) // 'default';

Of course, with functions, you can also do

my $value = $hash{$arg} // func($arg) // 'default';

Replies are listed 'Best First'.
Re^4: Sequential defined-or operators
by naikonta (Curate) on Jan 16, 2008 at 16:54 UTC
    Yes, I'm aware about this issue. I wrote related matter sometime ago. So I believe it will be perfectly fine to write:
    my $value = $hash{$key} // func $arg // 'default';
    knowing that func is a unary operator.

    Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://662281]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2018-03-24 03:36 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (297 votes). Check out past polls.