On Wed, Aug 11, 2021 at 05:27:16PM +0200, H.Merijn Brand wrote: > On Wed, 11 Aug 2021 10:41:58 -0400, James E Keenan <jkeenan@pobox.com> > wrote: > > > Since the last time this came up was several years ago, would it be > > possible to provide a one-paragraph explanation for the rationale for > > the feature? > > Consistency. Essentially, when // was introduced, the low-level > operator was forgotten. > > In my life as perl user I have never ever needed or used xor, but I > have used err while it was defined many many times. It is about making > easy (but ugly) things even easier and more consistent. > > Low-level precedence operators enable coders to use less line noise. > > foreach my $value (get_values ($foo)) { > my $v = convert_value ($value) dor next; # "" and 0 are ok > # ... > } I will suggest to anyone who cares to listen that low-level operators should only be used for flow control and high-level operators should only be used in conditions. Not having a low-level // operator breaks this consistency. In the example above // may safely be used, but only because of the parentheses around $value. In the analogous real-world example which caused me to publicly lament the lack of this feature convert_value returned either undef or a scalar blessed into a class which overloaded "" in a relatively expensive fashion. This meant that my $v = convert_value ($value) or next; whilst functionally correct, was expensive in the case of a true value being returned and the "or" needed to be changed to // despite the function never returning any other false value. I would assume that dor would not call the stringification method on the object. (Yes, the class should probably overload bool, or turn off fallback, or ..., but that's not the point here.) So the arguments for a low-level // operator are basically the same as the arguments for any other low-level operator. Plus consistency. -- Paul Johnson - paul@pjcj.netThread Previous | Thread Next