The double foreach loop is a whole lot easier to read though ;-)

I don't know. Maybe for a newbie, but I don't find it so. I have no trouble reading slice syntax -- I use it a lot -- and find the way it extends from 1D to 2D and so on, very natural and readable.

More importantly, I prefer the single line syntax to the multi-line because it makes it very clear that this is simply initialising the HoHs to a bunch of 1s, and nothing more. I like that I can read as "Initialise the 2D hash to 1s". There is little opportunity to misread the intent and screw it up by injecting extra stuff in the loops.

It would be even nicer if I could do (something like):

my %netifaces{ @eths }{ @nets } = (1) x *;

My point I guess is that this initialisation (whilst possibly important), is essentially a trival part of the overall algorithm, and having it as a single line gives it a weight commensurate with that.

Conversely, spreading it out over 5 lines with named iterators makes it take on a weight that makes it seem far more significant than it is in the overall scheme of things.

Ie. This is but a single step in the algorithm, and having it as a single line in the source code makes that very clear. Which I like, and feel is helpful when reading the overall algorithm.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^3: I hate nested loops by BrowserUk
in thread I hate nested loops by rastoboy

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.