# # # # # # # # # # #
# 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 !
-
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.
|