Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

comment on

( [id://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

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-03-28 23:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found