Hash::Slice can make a hash from a deep slice of another hash.
SYNOPSIS
use Hash::Slice qw/slice cslice/;
# A trivial example
my %hash = (a => 1, b => 2, c => 3);
my $slice = slice %hash, qw/a b/;
# $slice is now { a => 1, b => 2 }
# A hairy example
my %hash = (a => 1, b => 2, c => { d => 3, e => 4 });
my $slice = slice %hash, qw/a/, [ c => qw/e/ ];
# $slice is now { a => 1, c => { e => 4 } }
# An even hairier example
my %hash = (a => 1, b => 2, c => { d => 3, e => 4, f => { g => 5, h => 6, k => [ 0 .. 4 ] } }, z => 7);
my $slice = slice %hash, qw/a z/, [ c => qw/e/, [ f => qw/g k/ ] ];
# $slice is now { a => 1, z => 7, c => { e => 4, f => { g => 5, k => [ 0, 1, 2, 3, 4 ] } } }
# Make a cloned-slice of %hash
my %hash = (a => 1, b => 2, c => { d => 3, e => 4, f => { g => 5, h => 6, k => [ 0 .. 4 ] } }, z => 7);
my $slice = cslice %hash, qw/a z/, [ c => qw/e/, [ f => qw/g k/ ] ];
$slice->{c}->{e} = "red"; # $hash{c}->{e} is still 4
Product's homepage
Requirements:
· Perl