Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Why so strict?

by Loops (Curate)
on Nov 12, 2014 at 03:21 UTC ( [id://1106933]=note: print w/replies, xml ) Need Help??


in reply to Why so strict?

What you're employing is the Ternary operator which has the form:

$variable = <condition> ? <value1> : <value2>;

The variable gets set to value1 if the condition resolves to true, or value2 if the condition resolves to false. So you should not be using "say" in either the value1 or value2 positions as you do in your example. So lets rewrite it without the say:

my $c = <true/false> ? "$c found!" : "None!";

And now the problem is clear, in the true case, you're trying to initialize $c to a value that contains _itself_. It's like saying my $c = $c, it's nonsensical.

Replies are listed 'Best First'.
Re^2: Why so strict?
by mikeh123 (Novice) on Nov 12, 2014 at 03:38 UTC
    Thanks to both of you for the clarity! For far too long I've thought of the ternary operator as, well, not an operator, but a concise shorthand for if/else. Perfectly and quickly answered; thanks for sharing the wisdom!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found