in reply to Re^2: Hash Splice
in thread Hash Splice
If you only want to remove one of the elements from the anonymous array (say the second element) in the hash element 'foo', you can do this: delete $hash{foo}[1];
BTW, to keep the values of the hash that you're deleting (in the %wanted hash), the delete function returns the key and value. Example: $wanted{foo} = delete $hash{foo}; Here's a complete example:
Produces the following output:my %wanted = (); my %hash = ( 'foo' => [1,2,3], 'bar' =>[3,4,5]); $wanted{foo} = delete $hash{foo}; print "Left-over:\n"; for $key (keys %hash) { print "$key, @{$hash{$key}}\n"; } print "Wanted:\n"; for $key (keys %wanted) { print "$key, @{$wanted{$key}}\n"; }
Good luck!Left-over: bar, 3 4 5 Wanted: foo, 1 2 3
|
|---|