Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Can If-then conditions do ($a = $b = $c) type expressions?

by snafu (Chaplain)
on Apr 25, 2002 at 17:04 UTC ( [id://162041]=note: print w/replies, xml ) Need Help??


in reply to Re: Can If-then conditions do ($a = $b = $c) type expressions?
in thread Can If-then conditions do ($a = $b = $c) type expressions?

Ahhh....yes. It didn't occur to me that ($a == $b) actually evaluates to true or 1 vs the value that they are set to which now makes sense. Excellent! Although, I do think that this kind of operation would be a nifty one to have available. It probably would be difficult to impossible to implement though.

_ _ _ _ _ _ _ _ _ _
- Jim
Insert clever comment here...

  • Comment on Re: Re: Can If-then conditions do ($a = $b = $c) type expressions?
  • Download Code

Replies are listed 'Best First'.
(Amel)Re: Re: Re: Can If-then conditions do ($a = $b = $c) type expressions?
by dsb (Chaplain) on Apr 25, 2002 at 17:15 UTC
    I don't know about easy to read but it can be done in a roundabout sort of way:
    $a = 5; $b = 5; $c = 5; if ((($a == $b ) + ($a -1)) == $c) { print "yes!!!\n"; }
    or better yet:
    # given three equal variables if (($a == $b ) == ($b == $c)) { print "yes!!!\n"; } # as pointed out by Sidhekin # given three different variables if (($a == $b ) == ($b == $c)) { print "yes!!!\n"; } # still prints 'yes!!!\n'. Why? # both sides evaluate to false or 0, # and 0 == 0 evaluates to true
    Again, I'm not saying I'd use this... ;0)

    Update: Thanks to Sidhekin for pointing out my misstep. It does work with 2 same and 1 different variable. ;0)




    Amel

      $a = 5; $b = 5; $c = 5; if ((($a == $b ) + ($a -1)) == $c) { print "yes!!!\n"; }

      Amel is one dangerous monk {grin} ... observe:

      $a = 6; $b = 5; $c = 5; if ((($a == $b ) + ($a -1)) == $c) { print "yes!!!\n"; }

      # given three equal variables if (($a == $b ) == ($b == $c)) { print "yes!!!\n"; }

      Yeah, right, "given three equal variables". Given three different variables, however ...

      $a = 6; $b = 4; $c = 5; if (($a == $b ) == ($b == $c)) { print "yes!!!\n"; }

      ++ for not saying you'd use this ;-)

      Update:... and here I had finally convinced myself Amel had to be joking ... oh well ...
      You're welcome to that ++ anyways — the joke is none the worse for being unintended ;)

      The Sidhekin
      print "Just another Perl ${\(trickster and hacker)},"

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found