Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Slicing a hash reference from a collection of hash references within a hash reference

by Anonymous Monk
on Oct 07, 2015 at 17:11 UTC ( [id://1144080]=note: print w/replies, xml ) Need Help??


in reply to Slicing a hash reference from a collection of hash references within a hash reference

And as far as "getting your head around references" goes, just remember that they are a special type of scalar that "refers to" something else. Anything can be referred-to, and everything has a reference-count so that it will not disappear until all references are gone. (Mumble about "weakened" references ...) And, as far as "in one line" goes, don't be too concerned about that. It is not "a sign of a newbie" to use more source-code lines.
  • Comment on Re: Slicing a hash reference from a collection of hash references within a hash reference

Replies are listed 'Best First'.
Re^2: Slicing a hash reference from a collection of hash references within a hash reference
by muba (Priest) on Oct 08, 2015 at 02:27 UTC
    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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1144080]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-25 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found