Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^4: RFC: "assignary" operator ?= :

by choroba (Cardinal)
on Dec 08, 2019 at 20:49 UTC ( [id://11109854]=note: print w/replies, xml ) Need Help??


in reply to Re^3: RFC: "assignary" operator ?= :
in thread RFC: "assignary" operator ?= :

> I like the compound operator x!!

It's a bit different than the if/else or ternary it's used to replace, though. Unlike them, the x!! evaluates the left hand side even if the condition is zero. Cf.

my $t; sub tuple { $t++ => 12 } my $bool = 0; my %h = (tuple()) x !! $bool;
versus
... my %h = $bool ? (tuple()) : ();

Now %h is the same, but $t is different.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

Replies are listed 'Best First'.
Re^5: RFC: "assignary" operator ?= :
by shmem (Chancellor) on Dec 08, 2019 at 21:03 UTC
    It's a bit different than the if/else or ternary it's used to replace, though

    Ah no, this construct doesn't replace any ternary, it is a wholly different thing - but an example for replacement of a convoluted construct with a succinct idiom. Once you grok what x!! is about, you'll never forget what it does.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-19 22:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found