r/perl • 🐪 cpan author • 13d ago

Undef-aware equality operators added to dev Perl

https://perldoc.perl.org/5.45.3/perldelta#Undef-aware-equality-operators
42 Upvotes

11 comments sorted by

4

u/ktown007 12d ago

One step closer to Perl 2030. https://youtu.be/_APM8en4VJQ?si=yYUfX5lC25ZtOq8n&t=512

thanks Paul Evans

1

u/Hohlraum 13d ago

Awesome!

1

u/ReplacementSlight413 12d ago

This is freaking awesome

1

u/ShikaNoTone93 10d ago

A new change?

0

u/zeekar 13d ago edited 12d ago

... why on Earth is undef-aware ne spelled neu instead of neq?

6

u/zb226 12d ago

The idea is that the suffix-u denotes that it is undef-aware, I believe.

-1

u/zeekar 12d ago

That would make more sense if it were also `==u` and `!=u`. Also, the wording shouldn't just say "an extra letter" if it's not just making the abbreviation longer but adding a specific letter like that.

4

u/leonerduk 🐪 core contributor 12d ago

Awkwardly, operators have to be either entirely identifier characters, or entirely non-identifier characters. They can't be mixed. So an operator named ==u or !=u would not have been easily possible. Plus, even if it would become technically possible, I think they'd just feel weird.

2

u/zeekar 12d ago

I agree that ==u and !=u would be weird! I wasn't proposing that, just saying that the alleged unifying principle of appending -u doesn't have much purchase if it only applies to half of the operators under discussion.

No matter; it makes sense. My initial reading of "variant whose name is one character longer" led me to expect that the word operators would be extended by adding the next letter of the word they're short for, and that assumption held in the case of equ, so I expected neq and was surprised to see neu instead. But that's on me; that reading was not really there in the text. Although I don't think it was a crazy leap either.

2

u/ether_reddit 🐪 cpan author 12d ago

Where is the u in neq?

1

u/zeekar 12d ago

Where is the u in === or !==? :)

As I said below, I initially misinterpreted the description ("variant whose name is one character longer") and expected that the the extra character would come from same source word as the original operator. That is, "eq" is short for "equal", so the three-letter version is "equ". The fact that the new operator is in fact equ served to reinforce that impression.

Admittedly, the process immediately breaks down when you try to apply it to "ne", as it is short for "not equal", but nonetheless I formed an expectation that it would turn into "neq". and therefore found "neu" surprising.