L
Lynn
Hi All,
I have a hash where the values are a list of lists. What I would like to do
is
convert this to a hash where the value is just a reference to an array that
contains
the list of lists. Below is my attempt to convert this to what I want, the
problem
is that I am loosing some people in the process!
use strict;
use warnings;
use Data:umper;
my %people = (
'hillrich' => [ [5308125], [2053628], [5312468], [5312492] ],
'hsieh' => [ [5312182], [5312613], [5312517] ],
'prakash' => [],
'florencb' => [
[1420688], [1420596], [5312242], [5306884], [5305217], [5248521],
],
'x_shukl' => []
);
my %new_format_people=();
foreach my $person(keys %people) {
foreach my $item (@{ $people{$person} }) {
for ( @$item) {
push @{$new_format_people{$person}},$_;
}
}
}
print Dumper(\%new_format_people);
output is:
$VAR1 = {
'hillrich' => [
5308125,
2053628,
5312468,
5312492
],
'hsieh' => [
5312182,
5312613,
5312517
],
'florencb' => [
1420688,
1420596,
5312242,
5306884,
5305217,
5248521
]
};
I lost prakash and x_shukl in the conversion process. How can I keep these
people
in the new hash I am creating?
Thanks
Lynn
I have a hash where the values are a list of lists. What I would like to do
is
convert this to a hash where the value is just a reference to an array that
contains
the list of lists. Below is my attempt to convert this to what I want, the
problem
is that I am loosing some people in the process!
use strict;
use warnings;
use Data:umper;
my %people = (
'hillrich' => [ [5308125], [2053628], [5312468], [5312492] ],
'hsieh' => [ [5312182], [5312613], [5312517] ],
'prakash' => [],
'florencb' => [
[1420688], [1420596], [5312242], [5306884], [5305217], [5248521],
],
'x_shukl' => []
);
my %new_format_people=();
foreach my $person(keys %people) {
foreach my $item (@{ $people{$person} }) {
for ( @$item) {
push @{$new_format_people{$person}},$_;
}
}
}
print Dumper(\%new_format_people);
output is:
$VAR1 = {
'hillrich' => [
5308125,
2053628,
5312468,
5312492
],
'hsieh' => [
5312182,
5312613,
5312517
],
'florencb' => [
1420688,
1420596,
5312242,
5306884,
5305217,
5248521
]
};
I lost prakash and x_shukl in the conversion process. How can I keep these
people
in the new hash I am creating?
Thanks
Lynn