Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^2: Better expression for $x = !!$y||0

by merlyn (Sage)
on Apr 19, 2005 at 14:07 UTC ( [id://449250]=note: print w/replies, xml ) Need Help??


in reply to Re: Better expression for $x = !!$y||0
in thread Better expression for $x = !!$y||0

Like others in this thread, you too are presuming the sanity of the ! return. In fact, ! can return 37 for true. There's no promise in the Perl docs otherwise.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

  • Comment on Re^2: Better expression for $x = !!$y||0

Replies are listed 'Best First'.
Re^3: Better expression for $x = !!$y||0
by ysth (Canon) on Apr 19, 2005 at 23:08 UTC
    I said shorter, I didn't say accurate :). But really, if you presume an overloaded ! that returns something other than perl's true and false values (and that's presuming an awful lot) there's nothing you can do to $y besides examine it in boolean context with if or ?:.
      Just to let you know we fixed this, in Perl 6 this is written:
      $x = ?$y;
      And the standard operators like == are expected to return 0 or 1 when a boolean result is expected. (Boolean context will still accept any true value, as in Perl 5, and the short-circuit operators still return one of the input values as the "true" value.),

      Yes, you can still overload these to return something other than 0 or 1, but it would be construed as antisocial.

        in Perl 6

        ...

        Yes, you can still overload these to return something other than 0 or 1, but it would be construed as antisocial.

        That's exactly how I feel WRT doing this in perl5.
      I said shorter, I didn't say accurate.
      If it doesn't need to be accurate, $x=1 is pretty short.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-24 01:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found