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

Re: Why so strict?

by Loops (Curate)
on Nov 12, 2014 at 03:21 UTC ( #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? | Other CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2022-05-18 12:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (70 votes). Check out past polls.

    Notices?