misterperl has asked for the wisdom of the Perl Monks concerning the following question:
I want a slice from a hash, in one step?
examples: GIVE ME A HASH (from another hash) that only includes keys beginning with 'cat'. Or where the value is > 10. I usually resort to this sort of ugliness:
my %h2;
for ( keys %h )
{
next unless /^cat/;
$h2{$_} = $h{$_};
}
Seems like there oughta be other easier way to slice this thing up in one line with some sorta
@h2{@something} = @something++
TY Monks
examples: GIVE ME A HASH (from another hash) that only includes keys beginning with 'cat'. Or where the value is > 10. I usually resort to this sort of ugliness:
my %h2;
for ( keys %h )
{
next unless /^cat/;
$h2{$_} = $h{$_};
}
Seems like there oughta be other easier way to slice this thing up in one line with some sorta
@h2{@something} = @something++
TY Monks
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Is there a simple syntax to logically slice a hash?
by BrowserUk (Patriarch) on Feb 21, 2013 at 15:49 UTC | |
Re: Is there a simple syntax to logically slice a hash?
by space_monk (Chaplain) on Feb 21, 2013 at 15:36 UTC | |
Re: Is there a simple syntax to logically slice a hash?
by Athanasius (Archbishop) on Feb 21, 2013 at 15:38 UTC | |
Re: Is there a simple syntax to logically slice a hash?
by tobyink (Canon) on Feb 21, 2013 at 15:42 UTC | |
Re: Is there a simple syntax to logically slice a hash?
by LanX (Saint) on Feb 22, 2013 at 01:50 UTC | |
Re: Is there a simple syntax to logically slice a hash?
by TomDLux (Vicar) on Feb 21, 2013 at 16:29 UTC | |
by BrowserUk (Patriarch) on Feb 21, 2013 at 16:41 UTC |
Back to
Seekers of Perl Wisdom