in reply to Re^2: map and grep (but for hashes)
in thread map and grep (but for hashes)
But slightly off the specs.
You're missing the " k = something," part of the spec :) How about?
#! perl -slw use strict; sub hmap(&%) { use vars qw[ $h ]; my $code = shift; my @rv; local( $h, $_ ) = splice( @_, 0, 2 ), push @rv, $h, $code->() while @_; return @rv } sub hgrep (&%) { use vars qw[ $h ]; my $code = shift; my @rv; local( $h, $_ ) = splice( @_, 0, 2 ), push @rv, $code->() ? ( $h, $_ ) : () while @_; return @rv; } my %h = 'a' .. 'z'; print %h; my %r = hmap{ ++$_ } %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^4: map and grep (but for hashes)
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 | |
|
Re^4: map and grep (but for hashes)
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 Corion (Patriarch) on Feb 01, 2009 at 20:15 UTC | |
by BrowserUk (Patriarch) on Feb 02, 2009 at 06:09 UTC | |
by zerohero (Monk) on Feb 02, 2009 at 17:57 UTC |