I second moritz' excellent suggestion for reading an excellent story.

I can't endorse your desire "to shorten the 'foreach' block" nor support your "need (for) a nice-looking, laconic ... solution. Perhaps "nice-looking," shoudl have come out, since we may have very different ideas of the meaning of that phrase. Note that I did remove "as much Perl-ish as possible" from the quote.

I did so because the "Perl-ish" solution should heed the advice to keep the code readily comprehensible; the warning that the individual writing a script do so as if the (future) maintainer would be a homicidal maniac who knows the original author's home address.

Something of the same meme is enbedded in this portion of The path to mastery:

"When you see the code of master Perl programmers you may be amazed at how few strokes of the keyboard they require to solve a problem completely. Many in error think that they should therefore constantly try to cram as much into as little room as possible.

"This is a misguided path." (emphasis supplied)

So read on, especially (jcwren) RE: The path to mastery by jcwren and, tangentially, dragonchild's Re^3: The path to mastery.

Update: added sentence re "nice looking" in para 2.


In reply to Re: get solution as short as possible by ww
in thread get solution as short as possible by Anonymous Monk

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.