in reply to MySQL hashes with same key
You don't *have* to use arrays. But it really depends on the result(s) you want. If you want all three comments to be tied to the same key, you could read your data like:
my $sth=$dbh->prepare("select ...."); $sth->execute; # Stuff all the data in a hash, concatenating all comments my %Macs; while (my $hr = $sth->fetchrow_hashref) { if (! exists $Macs{$$hr{mac}}) { $Macs{$$hr{mac}} = $$hr{comment}; } else { $Macs{$$hr{mac}} .= $$hr{comment}; } }
You could have each hash key hold an array of comments, too. It all boils down to how you're actually going to work with the data.
...roboticus
When your only tool is a hammer, all problems look like your thumb.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: MySQL hashes with same key
by jcrush (Acolyte) on Nov 16, 2012 at 05:34 UTC |