Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
# # # # # # # # # # # # SQL MAC Query # # # # # # # # # # # # our $smq = $dbh->prepare("select distinct mac,comment from arp.filter where operation = 'filter' order by mac") or die "Couldn't prepare statement: " . $dbh->errstr; # # # # # # # # # # # # # # # # # SQL Distinct MAC Table # # # # # # # # # # # # # # # # # $smq->execute() or die "Couldn't execute statement: " . $smq->errstr; print "# SQL Distinct MAC HASH #\n"; # +----------------+-------------------------------------+ # | mac | comment | # +----------------+-------------------------------------+ # | 1226.b0ab.317e | roving filtered mac | # | 1226.b0ab.317e | roving filtered mac [force filter | # | 1226.b0ab.317e | [thor2] Excessive Campus Bandwidth | # +----------------+-------------------------------------+ # 3 rows in set (0.04 sec) our $mac_t = "1226.b0ab.317e"; my $ref = $dbh->selectall_hashref("select distinct mac,comment from arp.filter where operation = 'filter' order by mac", 'mac'); foreach my $id (keys %$ref) { if ($mac_t eq $ref->{$id}{mac}) { print "Found a row: mac = $ref->{$id}{mac}, comment = $ref->{$id}{comment}\n"; } }
The results printed are missing all 3 rows of data
# SQL Distinct MAC HASH # Found a row: mac = 1226.b0ab.317e, comment = [thor2] Excessive . . . # END SQL Distinct MAC HASH #
Am I forced to use Arrays, and if so how is the best way to do that?
If using an Array
What happens if I want search one address, and print out all comments attached to that one mac address? (Reason for my hash usage)
For example, if I have 100 macs, and if one is in the database, then print out all the comments on that mac. Thank You, very much for the help Perl Monks !

In reply to MySQL hashes with same key by jcrush

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (9)
As of 2024-04-23 11:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found