Mailing List Archive

for perl 7
Hello!

I beg you pardon for my poor English.

I have had some little contact with brian d foy and I write to you now! I have a little syntactic suggestion for perl 7. Indeed, I often find myself writing things similar to

if ($foo ne $baz) {$foo = $baz; doSomething};

which is a little verbose for my taste and does not feel syntactically optimally perlish. I do not want (to) "doSomething" if $foo already was equal to $baz since before. Some perlers would probably argue for a construct similar to

doSomething if ($foo ne $baz, $foo = $baz)[0];

but I choose not to call it perlish either. Indeed I would prefer a more concise (and perlish?) syntax similar to

doSomething if ($foo =ne $baz);

where =ne would:

• check if $foo and $baz are different and temporarilly store the result of this comparison "somewhere".

• assign $baz into $foo

• return the result of the comparison previously stored (above)

This syntax would of course also call doSomething if $foo and $baz were different before the line was interpreted.

I suggest not to use the syntax

$foo ne= $baz;

which could risk to be (mis)understood as

$foo = $foo ne $baz;

Thus, if you like the syntactic idea of

doSomething if ($foo =ne $baz);

then feel free to introduce it into Perl 7! ? You do not need to refer to me and say it was my idea, but if you want to refer to me, that's equally OK.

Of course, this suggestion could be extended to

=cmp

or similar for numeric comparisons.

Kind regards!

Saašha,
Re: for perl 7 [ In reply to ]
2021-8-10 11:59 Saašha Metsärantala <saasha@acc.umu.se> wrote:

>
> where =ne would:


Saašha

Hello!

Thank you for posting your idea!

Personally, I feel comparison operator and equal operator combination is a
little difficult.

Listen to other people's conversations as well.
Re: for perl 7 [ In reply to ]
On Mon, Aug 9, 2021, at 1:28 PM, Saašha Metsärantala wrote:
> doSomething if ($foo =ne $baz);
>
> where =ne would:
>
> • check if $foo and $baz are different and temporarilly store the result of this comparison "somewhere".
>
> • assign $baz into $foo
>
> • return the result of the comparison previously stored (above)

Saašha,

Thanks for writing. My concern is that this feels like a fairly special case, and that producing a very compact syntax will force the reader of Perl to learn even more syntax, rather than to rely on the existing syntax. New dense syntax should be reserved for very powerful or common operations, and my feeling is that this is neither.

--
rjbs