I find it highly upsetting that the >= operator does not act in the same manner as the += operator. How on earth can I write code like $x = $x > $y; more compactly? I can't!

If only all A OP= B operators worked like A = A OP B, then Perl would be so much more consistent.

Disclaimer: Take a deep breath, chuckle, and go your merry way.

japhy -- Perl and Regex Hacker

Replies are listed 'Best First'.
Re: fixing Perl's inconsistencies
by extremely (Priest) on Feb 20, 2001 at 05:18 UTC
    ++ japhy, this made my day... Of course, with all the OOP stuff I've been doing I wish that I could set a scalar equal to a reference to itself ala: $x \= $x; That would help immensely for those cases where I have a plain scalar and need a scalar ref...

    Update: While we are at it, we should work out good uses for the "reverse comma" '<=', and the "back arrow" '<-' since we use their forward versions so much...

    You are all aware these are jokes, right? I got a couple of messages that worried me...

    --
    $you = new YOU;
    honk() if $you->KnowI'mKiddingAboutThatOp(perl)

Re: fixing Perl's inconsistencies
by mirod (Canon) on Feb 20, 2001 at 12:41 UTC

    Actually I think += and especially -= should be modified. None of them makes much sense when used on a string, so they should behave this way:

    my $string= "mirod"; $string += " is dumb"; # $string is now "mirod is dumb" $string -= "Sure "; # $string is now "Sure mirod is dumb"

    Although I know this would start a religious war with those who want -= to behave like this:

    $string="I am _not_ dumb"; $string -= "_not_ "; # now guess what's in $string?

    I am ready to compromise and go for the second version only if >> and << are re-used too (after all who uses them on strings?) for my original proposal:

    my $string= "can"; $string >> " compromise"; # $string is now "can compromise" $string << "I "; # $string is now "I can compromise"

    As for <= of course it should do a deep copy of a reference while for consistency <- would do a shallow copy (just like = does).

Smiling Evilly
by gryng (Hermit) on Feb 20, 2001 at 05:12 UTC
    I smile evilly at you japhy.

    Of course, in my case, it was >= being mistaken for shift right :) .

    Ciao,
    Gryn

Re: fixing Perl's inconsistencies
by Tyke (Pilgrim) on Feb 20, 2001 at 13:23 UTC
    Nah, you got it the wrong way round: $a += $b should be a relational operator like $a >= $b. It obviously has the semantic $a is more positive than $b, so it has an obvious application in fuzzy logic algorithms where we want to know which of two states is more likely to be true.
Re: fixing Perl's inconsistencies
by tadman (Prior) on Feb 20, 2001 at 15:14 UTC
    If only there was an easier way to say things like:
    $x = $y if ($y > $x);
    If '$y' is some sort of monster HoH reference, you can see how that would simplify programming at the expense of a simple syntax. :-) Perhaps:      $x =?> $y; Err, or not.

    Maybe for the ObfPerl crowd, you could just make up your own operators, just like that!
(tye)Re: fixing Perl's inconsistencies
by tye (Sage) on Feb 20, 2001 at 22:05 UTC

    Heh. Yesterday I wrote $x=~0;.

            - tye (but my friends call me "Tye")
      Hmm? $x =~ 0 would be like $x = $x ~ 0, and ~ is unary. No go. ;).

      I ran a funny problem, though, with that operator. I was neatening somebody's code:
      $this=someFunc(); $that=result($this); $that=~s/(\d+)/data($1)/eg;
      And I just padded the = with whitespace:
      $this = someFunc(); $that = result($this); $that = ~s/(\d+)/data($1)/eg;
      And was baffled momentarily when $that started holding a large number. Then I noticed that number seemed a lot like bitwise negation of 0. D'oh.

      japhy -- Perl and Regex Hacker

        japhy, just in case you didn't get it... Why would anyone write $x =~ 0? The code I wanted was $x= ~0. It is just the flip side to what you are asking for: There are already enough ambiguities. (And I found it mildly amusing.)

                - tye (but my friends call me "Tye")