On 5/22/06, Michael Gargiullo <[EMAIL PROTECTED]> wrote:
It's been a while since I've used Perl and I need some help with a
multidimensional array.

I have a file that I need to compile some stats on.

I need to keep track of 'actions' and 'rules'.  Yes, stats from a
firewall.

Both 'actions' and 'rules' need to be dynamic so if a rule is added,
it's automatically dealt with.

As I loop through the file I have both the current action and rule as a
variable.

I've tried to store them several ways...


my @actionrule;
$actionrule[$action][$rule]++;

In order for this to work as you expect, $action and $rule need to be
numeric. Is that the case? If not, do you need to preserve the order?

I need some kind of loop to extract the data. I also need to know what
the action and rule of each count is.

I've tried a few while and foreach loops without success.

Within the loop I need to build a query (per record).

$query="insert into tmpfw set action=$action, rule=$rule, count=$count";

foreach $first (@actionrule){
  foreach(@first){
    print $_."\n";
  }
}

You need to add 'use strict;' at the top of your program. Not only
will that help you see if you've made a typo, it will help us be able
to debug your program better. Also read this:
 <http://perldoc.perl.org/perlreftut.html>

for my $rule (@actionrule) {
   for my $i (@$rule) {
       # do stuff
   }
}

Not only does it not print the counts, but how do I get the action and
rule associated with it?

Thanks,

Mike

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to