Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Pls more operators, e.g. <&&=

by rsFalse (Hermit)
on Nov 15, 2018 at 14:57 UTC ( #1225859=perlmeditation: print w/replies, xml ) Need Help??

Good day, monks.

I've seen that Perl likes operators and have plenty. I was amazed after I saw new in 5.22 (Bitwise String Operators).
And I remember that usually I use to write '$max < $c and $max = $c;' (if not using List::Util qw( max )), which is self repeating. And my idea was to somehow shorten such statements. Here I suggest an operator which shortens previous statement, e.g. these two code would be equivalent: '$max < $c && ( $max = $c );' === '$max <&&= $c;'. New operator '<&&=', with other similar variants: '>&&=', '<=&&=', '>=&&=', and 4 more with '||' in the middle, although they are redundant. Associativity could be the same as of other assignment operators. Another construct suggestion for same operations, would be this: '(comparison_op.)=', which means, that any comparison op can be written inside parentheses, and it corresponds to: '$max comparison_op. $c and $max = $c;'. Isn't this bad idea?

Replies are listed 'Best First'.
Re: Pls more operators, e.g. <&&=
by johngg (Canon) on Nov 15, 2018 at 18:59 UTC

    I don't really like this idea. Perl gets enough "looks like line noise" flak without adding four- and five-character operators to the mix.

    If we were running a poll, the feature I would like to see added to the language is a new function analogous to chop that acts on the beginning of a string rather than the end.



      I think there is a module that implements chip and chimp but I cannot remember the name.


      You can lead your users to water, but alas, you cannot drown them.
        I agree with this idea. Of course "chip" and "chimp" has its regex alternatives like s/.//s and s/\A${chop}//s, but they could be implemented as standard functions.
        It's a bit of topic, but function which zips two arrays also should be available as a standard function.
Re: Pls more operators, e.g. <&&=
by hippo (Chancellor) on Nov 15, 2018 at 15:07 UTC

    Could you explain what you perceive to be the added value in this?

      I thinks it is minor value. It shortens the code (a little) in according with "Don't repeat yourself".
        Classic misunderstanding of dont repeat yourself

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://1225859]
Approved by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2021-03-05 11:15 GMT
Find Nodes?
    Voting Booth?
    My favorite kind of desktop background is:

    Results (109 votes). Check out past polls.