# # # # # # # # # # #
# 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 ArrayWhat 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 !
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Outside of code tags, you may need to use entities for some characters:
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|