Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^5: A more elegant way to filter a nested hash?

by LanX (Saint)
on May 31, 2018 at 19:11 UTC ( [id://1215563]=note: print w/replies, xml ) Need Help??


in reply to Re^4: A more elegant way to filter a nested hash?
in thread A more elegant way to filter a nested hash?

I count the slice as iteration. It's fast but doesn't come without a price.

I also think there are differences in error handling, a missing value will be reported as undef when you slice, without raising an error.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

  • Comment on Re^5: A more elegant way to filter a nested hash?

Replies are listed 'Best First'.
Re^6: A more elegant way to filter a nested hash?
by Veltro (Hermit) on May 31, 2018 at 20:15 UTC

    What price is higher then using map or grep? I don't see it. The only iteration that is done twice is over the keys of the result-set which is necessary because of autovivification. The fact that missing values become undefined instead of non-existent is actually something that I would prefer in case the filter asked for it.

    2018-06-09 Athanasius restored node content

      But the op wanted to croak on different types.

      IMHO all the edge cases are easier covered with a for loop over the filter and if-else chains.

      Just my 0.02$

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        I agree with you. But I don't understand why you are ignoring my point that I am trying to make. The point regards the answer that gets the highest amount of votes regards using map and grep in favor of using hash slices!

        I don't know what you mean with 'edge cases' but if you mean checking for hashes or undefined values they can easily be added with some simple if then else statements. E.g.:

            if ( !defined $n->{ $_ } && exists $f->{ $_ } ) { print "Hello a undefined value was detected\n" ; }

        2018-06-09 Athanasius restored node content

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (None)
    As of 2024-04-19 00:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found