Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: conditional print. Is correct to use it?

by duelafn (Parson)
on Oct 27, 2020 at 12:01 UTC ( [id://11123204]=note: print w/replies, xml ) Need Help??


in reply to conditional print. Is correct to use it?

In my opinion, the only thing to do with unexpected values is die:

# ... but something forrible happens instead... die "Expected a value for fo" unless defined($fo) and length($fo);

Hard crashes have a way of getting fixed quickly. Anything else tends to cause odd behavior that is hard to track down.

Note: $fo is initiaslized to an empty string. Use just my $fo; do declare an uninitialized (undefined) value.

In response to "we have 8 beans", ($fo + 0 || 8) is parsed as ($fo + (0 || 8)) due to precedence. Update: silly me, ignore this.

Good Day,
    Dean

Replies are listed 'Best First'.
Re^2: conditional print. Is correct to use it?
by choroba (Cardinal) on Oct 27, 2020 at 12:06 UTC
    > ($fo + 0 || 8) is parsed as ($fo + (0 || 8)) due to precedence.

    It's not.

    perl -MO=Deparse,-p -e 'print $fo + 0 || 8' print((($fo + 0) || 8));

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2024-04-16 10:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found