M
mike
If I am iterating over a set of data and I'd like to put that data into
a hash.
My data would be:
fred 578 great
fred 579 cool
sue 765 super
sue 766 yuppy
sue 767 puppy
As I iterate over that data loading it to the hash:
while ( @row = $sth->fetchrow() )
{
$TV{$row[0]} = { uid=>$row[0], ids => [ id=>$row[1], title=>$row[2]]
};
}
I think my hash then "should" look like:
%TV =
(
"fred" =>
{
uid => "fred",
ids => [
{ id => "578", title => "great", },
{ id => "579", title => "cool", },
],
},
"sue" =>
{
uid => "sue",
ids => [
{ id => "765", title => "super", },
{ id => "766", title => "yuppy", },
{ id => "767", title => "puppy", },
],
},
);
Then as I display that data:
foreach my $key ( keys %TV )
{
print "$TV{$key}{uid} @{ $TV{$key}{ids} }\n";
}
Only bad thing is only the first uid gets loaded so I'm only getting:
fred 578 great
sue 765 super
Any help is appreciated.
Mike
a hash.
My data would be:
fred 578 great
fred 579 cool
sue 765 super
sue 766 yuppy
sue 767 puppy
As I iterate over that data loading it to the hash:
while ( @row = $sth->fetchrow() )
{
$TV{$row[0]} = { uid=>$row[0], ids => [ id=>$row[1], title=>$row[2]]
};
}
I think my hash then "should" look like:
%TV =
(
"fred" =>
{
uid => "fred",
ids => [
{ id => "578", title => "great", },
{ id => "579", title => "cool", },
],
},
"sue" =>
{
uid => "sue",
ids => [
{ id => "765", title => "super", },
{ id => "766", title => "yuppy", },
{ id => "767", title => "puppy", },
],
},
);
Then as I display that data:
foreach my $key ( keys %TV )
{
print "$TV{$key}{uid} @{ $TV{$key}{ids} }\n";
}
Only bad thing is only the first uid gets loaded so I'm only getting:
fred 578 great
sue 765 super
Any help is appreciated.
Mike