http://www.perlmonks.org?node_id=1218688


in reply to Syntax Perl Version support $c = () = $a =~ /\./g

And wouldn't it be the perfect thing to put in a descriptively-named one line subroutine that hides the Perl-voodoo in only one place, and tells everyone else exactly what it's supposed to do? Mmmmm....? Perl has lots of ways to write something such that you don't know at a glance what it's supposed to do, and it doesn't actually do what you intended for it to do or thought that it did, either. Sure would be nice to be able to fix any problems in one place.

Replies are listed 'Best First'.
Re^2: Syntax Perl Version support $c = () = $a =~ /\./g
by Your Mother (Archbishop) on Jul 17, 2018 at 20:50 UTC
    Perl has lots of ways to write something such that you don't know at a glance what it's supposed to do

    Well… Perl programmers do. It's weird… it's like this site is almost dedicated to those people. Maybe a name change would help combat the lack of clarity perptually befuddling you. s/Perl Monks/Perl Programmers Who *Like* Perl and Also Enjoy Learning, Exploring Problems, and Helping Their Community; Unemployable PMs Are Welcome to Participate Providing They Remain Respectful and Don't Become Founts of Acrimony or Wasted Time for Years on End/g;

Re^2: Syntax Perl Version support $c = () = $a =~ /\./g
by h2 (Beadle) on Jul 17, 2018 at 20:03 UTC

    Anonymous monk, and that is precisely where that is being placed, inside of a one liner utility subroutine, that is documented as to what it tests, in this case, it returns 1, true, if the match is correct, and undefined, false, if not. As part of a larger test, but as a one liner. I have used arcane syntax like this internally in utility tools, and try to keep it out of the main logic that would be likely to get patches or pull requests. Documented, with comments, etc.

    Now that this is confirmed safe, I'll be extending its use for all numeric tests (which is what this particular case is doing), and look into more secret type constructions for various utilities, that are not meant to be end user readable or serviceable, but are meant to be very very fast.

      Note that the content of the "anonymous" reply you replied to indicates it was authored by our Worst Nodes champion - who's recently introduced an annoying new tactic of replying "anonymously" ... and then sometimes agreeing with himself by replying to the "anonymous" post as sundialsvc4! I don't know why he's started doing this only recently.

      FWIW, I've often used the goatse operator in production code at work without wrapping it in a sub - though I always provide a one-line comment pointing to the goatse operator documentation. Having discussed the use of this operator during code reviews with a number of serious C++ programmers (but occasional Perl programmers) at work, I can report they've all been happy with this approach because, as skilled programmers, once they became aware it's a standard Perl idiom, they found the perlsecret documentation clear and easy to understand.

        In my case, I do want this wrapped up and safely out of view, because the potential contributors would be confused by such syntax, plus I do actually want it used as a utility subroutine to avoid scattering this type of stuff around the program, specifically to be able to update/tweak/optimize these tools as I go along. But thanks for the heads-up.
Re^2: Syntax Perl Version support $c = () = $a =~ /\./g
by Anonymous Monk on Jul 24, 2018 at 18:21 UTC
    "and tells everyone else exactly what it's supposed to do?" It does. You big dummy.