Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re: MySQL hashes with same key

by roboticus (Chancellor)
on Nov 16, 2012 at 03:30 UTC ( #1004116=note: print w/ replies, xml ) Need Help??

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.


When your only tool is a hammer, all problems look like your thumb.

Comment on Re: MySQL hashes with same key
Download Code
Replies are listed 'Best First'.
Re^2: MySQL hashes with same key
by jcrush (Acolyte) on Nov 16, 2012 at 05:34 UTC
    Thank you for your response. I would like to print out a list of comments for one address. If I search for mac aaaa.aaaa.aaaa.aaaa Printout Mac: aaaa.aaaa.aaaa.aaaa Comments: filtered for virus filtered by dmca filtered for excessive bandwidth filter on spoofed mac Thanks again.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1004116]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2015-10-09 10:12 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (237 votes), past polls