Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: How to filter few key value pairs from hash reference

by jaypal (Beadle)
on Sep 15, 2014 at 22:10 UTC ( [id://1100655]=note: print w/replies, xml ) Need Help??


in reply to Re: How to filter few key value pairs from hash reference
in thread How to filter few key value pairs from hash reference

Thanks CountZero for the suggestion. This was just a learning exercise where I was looking for copying a subset of a hash. Typically, I would use a hash slice but here I was looking to copy the key value pairs.

The map solution posted by choroba seems to be exactly what I needed (without creating a temporary copy of hash reference) though impairs readability (probably due to ternary op). Solution by JohnGG looks promising and quite readable but may not scale well if we have large sets of key value pairs to keep.

Still hoping to find a sweet spot between the two solutions.

  • Comment on Re^2: How to filter few key value pairs from hash reference

Replies are listed 'Best First'.
Re^3: How to filter few key value pairs from hash reference
by choroba (Cardinal) on Sep 16, 2014 at 08:21 UTC
    Typically, I would use a hash slice
    Time to upgrade to 5.20, it seems: New slice syntax.
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

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

    No recent polls found