Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: Is there a simple syntax to logically slice a hash?

by LanX (Bishop)
on Feb 22, 2013 at 01:50 UTC ( #1020045=note: print w/replies, xml ) Need Help??

in reply to Is there a simple syntax to logically slice a hash?

define your own hgrep!
$a=key $b=value
DB<142> sub hgrep (&%) { my $f=shift; my @res; local ($a,$b); while ( ($a,$b)= splice(@_,0,2) ) { push @res, $a => $b if $f->() } return @res } DB<143> %h = ( cat=>0, cut=>1, caty=>2 ) => ("cat", 0, "cut", 1, "caty", 2) DB<144> hgrep { $a =~ /^cat/ } %h => ("cat", 0, "caty", 2) DB<145> hgrep { $b>1 } %h => ("caty", 2)

Cheers Rolf

UPDATE: see Hash::MostUtils for a similar approach.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1020045]
[Discipulus]: good morning nuns and monks!
[marioroy]: Morning Discipulus. porting C code to Perl is an interesting problem for running parallel. I will try and the reason for attempting Perl code to match C 100%.
marto waves
[Discipulus]: hello marioroy! yes i need to start to write parallel, but not with this Pi code; it is yet melting my brain on it's own!

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (7)
As of 2017-10-24 07:08 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (286 votes). Check out past polls.