Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
It is not "a sign of a newbie" to use more source-code lines.

To the contrary, indeed. Just recently, I was hacking together a piece of code that featured a map within a map. Sure, the whole thing fitted on one "line", if your definition of "line" is somewhat liberal:

$some_object->one_method->other_method( [map { ... } map {...} @$sourc +e_aref] )

Which, in reality, looked more like:

$some_object->one_method->other_method( [ map { ... } map { ... } @$source_aref ]);

But then I was looking at it, and I shook my head. Sure, it worked. But was it "clean" code? Not by a long stretch: I could either slap multiple lines on comments on it, explaining what was going on, or refactor the whole thing:

use subs qw( fribble_aref frobble_aref ); my $results_aref = fribble_aref frobble_aref $source_aref ; my $other_object = $some_object->one_method; $other_object->other_method( $results_aref ); sub fribble_aref { return [map { ... } @{+shift}]; } sub frobble_aref { return [map { ... } @{+shift}]; }

The final solution definitely took more lines, but it also was way more comprehensible.

In reply to Re^2: Slicing a hash reference from a collection of hash references within a hash reference by muba
in thread Slicing a hash reference from a collection of hash references within a hash reference by nysus

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (7)
    As of 2021-05-09 11:01 GMT
    Find Nodes?
      Voting Booth?
      Perl 7 will be out ...

      Results (100 votes). Check out past polls.