in reply to map and grep (but for hashes)
Not pre-existing, but something along these lines?
#! perl -slw use strict; sub hmap(&%) { use vars qw[ $h $v ]; my $code = shift; my @rv; local( $h, $v ) = splice( @_, 0, 2 ), push @rv, $code->() while @_; return @rv } sub hgrep (&%) { use vars qw[ $h $v ]; my $code = shift; my @rv; local( $h, $v ) = splice( @_, 0, 2 ), push @rv, $code->() ? ( $h, $v ) : () while @_; return @rv; } my %h = 'a' .. 'z'; print %h; my %r = hmap{ $h => ++$v } %h; print %r; my %s = hgrep{ $h le 'm' } %r; print %s; __END__ [19:25:50.05] C:\test>hmap wxefabmnstyzuvcdklqrghijop egwyacmosuyaauwcekmgiqsoqik egcekmacgimoik
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: map and grep (but for hashes)
by shmem (Chancellor) on Jan 30, 2009 at 20:51 UTC | |
by BrowserUk (Patriarch) on Jan 30, 2009 at 21:07 UTC | |
by shmem (Chancellor) on Jan 30, 2009 at 22:23 UTC | |
by ikegami (Patriarch) on Jan 30, 2009 at 23:58 UTC | |
by shmem (Chancellor) on Jan 31, 2009 at 00:09 UTC | |
by zerohero (Monk) on Jan 30, 2009 at 21:14 UTC | |
by BrowserUk (Patriarch) on Jan 31, 2009 at 00:30 UTC | |
by zerohero (Monk) on Feb 01, 2009 at 20:07 UTC | |
| |
by zerohero (Monk) on Jan 30, 2009 at 21:00 UTC | |
|
Re^2: map and grep (but for hashes)
by zerohero (Monk) on Jan 30, 2009 at 20:58 UTC |