Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Why so strict?

by MidLifeXis (Monsignor)
on Nov 12, 2014 at 14:20 UTC ( [id://1106978]=note: print w/replies, xml ) Need Help??


in reply to Why so strict?

There is also a possible precedence issue with your statement. If you meant:

$c = &func(); $c ? say "$c found!" : say "None!";
and not
$c = (&func() ? say "$c found!" : say "None!");
then you got it wrong. ?: has a higher precedence than assignment (see perlop), so the ternary operator binds tighter to its operands than does the assignment operator. The ternary operator is handled first, then the assignment operator. To illustrate, try
perl -Mstrict -E 'sub func {5}; my $c; my $results = ( $c=func() ? 1 : + 2); say $c, "\t", $results'
and
perl -Mstrict -E 'sub func {5}; my $c; my $results = ( $c=func()) ? 1 +: 2; say $c, "\t", $results'

--MidLifeXis

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2024-04-23 15:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found