Beefy Boxes and Bandwidth Generously Provided by pair Networks BBQ
laziness, impatience, and hubris
 
PerlMonks  

Re: MySQL hashes with same key

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


in reply to MySQL hashes with same key

jason.c.rochon:

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.


Comment on Re: MySQL hashes with same key
Download Code
Re^2: MySQL hashes with same key
by jcrush (Novice) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (10)
As of 2014-04-18 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (466 votes), past polls