troubleshooting Question

Hash of Array slices?

Avatar of gmanpert
gmanpert asked on
Perl
6 Comments4 Solutions248 ViewsLast Modified:
I have a hash of Array as follows:

 keys = var1   var2  var3
            ---------------------
             1       a       john
             2       b       kim
             3       c       tim

such that

$value_ref = $hash{'var1'};
@values = @$value_ref;
print "Values: @values \n";

prints  1 2 3

What I'm trying to figure out is how to get a different hash, ( a simple hash - not a hash of arrays)
which has the same keys and just the values for the second row.   I want to end up with

$hash{'var1'} = 2;
$hash{'var2'} = 'b';
$hash{'var3'} = 'kim';

That is, I'd like to take a slice of the original hash, if there is such a thing?
Obviously, what I've done would work if I assigned a different name to $hash.  But this isn't really what I'm
looking for.  Thus, what I am looking for is the syntax which will let me do this simply and efficiently.

-G


Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 4 Answers and 6 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros