Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: RFC: "assignary" operator ?= :

by tobyink (Canon)
on Dec 08, 2019 at 21:47 UTC ( [id://11109858]=note: print w/replies, xml ) Need Help??


in reply to RFC: "assignary" operator ?= :

You can think of it as an "upgrading" operation for a boolean variable.

Like if a variable contains a Perl boolean, you can upgrade it to a JSON boolean:

$var ?= JSON::PP::true : JSON::PP::false;

Or you can upgrade a Perl boolean to some HTML:

my $is_ready = 1; $is_ready = 0 if $service->not_configured(); $is_ready = 0 if $service->payment->status() ne 'paid'; $is_ready ?= '<span class="green">yes</span>' : '<span class="red">no< +/span>'; print "<p>Service ready? $is_ready</p>";

Replies are listed 'Best First'.
Re^2: RFC: "assignary" operator ?= :
by Anonymous Monk on Dec 09, 2019 at 02:18 UTC

    convoluted? contrived? dilluted? word? ... unconvincing example

    my $is_ready = 1; $is_ready = 0 if $service->not_configured(); $is_ready = 0 if $service->payment->status() ne 'paid'; $is_ready or print "<p>Service ready? <span class="red">no</span></p>"; $is_ready and print gettext('yes ready');

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-18 02:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found