This may be better posted in Meditations. It sort of touches on both ponderings and obfuscations. I was prototyping an algorithm the other day when I developed a rather obfuscated method for building a hash from two lists. While this is not exactly a full "obfu", I certainly think the behavior could be incorporated into a full obfu. This seems to actually get in to the "what the heck is happening here?" as ysth, gryphon, and especially diotalevi have commented on perverseness of the construct. Without further ado:

push( @{ $y{ ($a = $_, ( grep {$a=~/$_/} @t )[0] || next)[1] } }, $_ ) + for @f;

The intent of this code is to take a list of patterns and a list of strings and group the strings based on pattern. It also needed to disregard any string that did not match any pattern.

In larger context, this line came from a bit of prototype code I was working on that was

use strict; my @t=qw(one two three); my @f=qw( one.ind.01 one.ind.02 one.tab.01 two.ind.01 two.tab.02 two.ind.02 three.ind.02 three.ind.01 three.tab.03 four1.ind four2.ind four2.ind f1v.ind.31 f1v.ind.32 f1v.ind.32 ); my %y; push( @{ $y{ ($a = $_, ( grep {$a=~/\b$_\.ind/} @t )[0] || next)[1] } +}, $_ ) for @f;

All monks previously mentioned (as well as others), were immediately revolted by such "offensive" code. diotalevi went on to say "Please tell me that you have never committed any code that actually looked like that!" He then went off to try to decipher how it actually worked. I do not think he ever found a satisfactory answer other than the next is a near-no-op with stack manipulation.

The line in question can be re-written in a much more verbose way:

So, what are the thoughts of other monks regarding this obscure construct? Perhaps more importantly, what does the Perl development community say about the behavior (both internal and external)? Is this asking for a future incompatibility? Is it firmly grounded or did I stumble on something that should not work?

Ivan Heffner
Sr. Software Engineer
WhitePages.com, Inc.

In reply to next in a post-fixed for by Codon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.