[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[no subject]



I do not mind mimicing the table with hashes and arrays as long as I do
not create.  For example in that whole table there are only 2 unique
user ids.  I do not want to create a user object for each row.  That
would yield way too many user objects that have the same data.

Here was one way I solved this problem:#
# Build our notification groups
#
my $dbase = DBI->connect($db_name, $db_user, $db_pass) or die
$DBI::errstr ;
my $res = $dbase->prepare($NG_SQL) or die $dbase->errstr ;
$res->execute or die $res->errstr ;
$res->bind_columns(\$cols[0], \$cols[1], \$cols[2], \$cols[3],
\$cols[4]) or die $res->errstr;
while ($res->fetch) {
  $NG{ $cols[0] }{ $cols[1] }{ 'id'} = $cols[1];
  $NG{ $cols[0] }{ $cols[1] }{ 'timeout'} = $cols[2];
  $NG{ $cols[0] }{ $cols[1] }{ 'users'}{$cols[3]} = $cols[4];
}


The reason why 'users' is a set of hashes is because there can be more
than one.  This seems to work but walking it is kludgy.

Here is my walking.

#
# Function walks the list of NG's
# and displays them
#
sub print_ng {
  my $a_ref = shift;
  foreach my $ref (sort keys %{$a_ref}) {
    print "NG: $ref\n";
    print "  Escalation Groups: \n";
    foreach my $ref2 (sort keys %{$a_ref->{ $ref }}) {
      foreach my $ref3 (sort keys %{$a_ref->{ $ref }->{ $ref2}}) {
        if ( $ref3 =~ /users/) {
          print "  Users: ";
          foreach my $ref4 (sort keys
%{$a_ref->{$ref}->{$ref2}->{'users'}}) {
            print "  $a_ref->{$ref}->{$ref2}->{'users'}->{$ref4} ";
          }
          print "\n";
        } else {
          print "  $ref3 = $a_ref->{$ref}->{$ref2}->{$ref3}\n";
        }
      }
    }
    print "\n";
  }
}


When I get into the hash of hashes I have to know if a key points to a
value or another hash.

So I want to mimic the data I just want to do it right.








</pre>
<!--X-Body-of-Message-End-->
<!--X-MsgBody-End-->
<!--X-Follow-Ups-->
<hr>
<ul><li><strong>Follow-Ups</strong>:
<ul>
<li><strong><a name="01224" href="msg01224.html">[ale] Organizing data</a></strong>
<ul><li><em>From:</em> phasefx at magusaptus.com (Jason Etheridge)</li></ul></li>
<li><strong><a name="01228" href="msg01228.html">[ale] Organizing data</a></strong>
<ul><li><em>From:</em> esoteric at 3times25.net (Geoffrey)</li></ul></li>
</ul></li></ul>
<!--X-Follow-Ups-End-->
<!--X-References-->
<ul><li><strong>References</strong>:
<ul>
<li><strong><a name="01209" href="msg01209.html">[ale] Organizing data</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
<li><strong><a name="01212" href="msg01212.html">[ale] Organizing data</a></strong>
<ul><li><em>From:</em> phasefx at magusaptus.com (Jason Etheridge)</li></ul></li>
<li><strong><a name="01213" href="msg01213.html">[ale] Organizing data</a></strong>
<ul><li><em>From:</em> cfowler at outpostsentinel.com (Chris Fowler)</li></ul></li>
<li><strong><a name="01220" href="msg01220.html">[ale] Organizing data</a></strong>
<ul><li><em>From:</em> phasefx at magusaptus.com (Jason Etheridge)</li></ul></li>
</ul></li></ul>
<!--X-References-End-->
<!--X-BotPNI-->
<ul>
<li>Prev by Date:
<strong><a href="msg01220.html">[ale] Organizing data</a></strong>
</li>
<li>Next by Date:
<strong><a href="msg01222.html">[ale] Any Squidguard for the Impatient on Debian Docs?</a></strong>
</li>
<li>Previous by thread:
<strong><a href="msg01220.html">[ale] Organizing data</a></strong>
</li>
<li>Next by thread:
<strong><a href="msg01224.html">[ale] Organizing data</a></strong>
</li>
<li>Index(es):
<ul>
<li><a href="maillist.html#01221"><strong>Date</strong></a></li>
<li><a href="threads.html#01221"><strong>Thread</strong></a></li>
</ul>
</li>
</ul>

<!--X-BotPNI-End-->
<!--X-User-Footer-->
<!--X-User-Footer-End-->
</body>
</html>