Suggestions welcome? Here they come :)

foreach($_){
foreach($_) is kind of useless, you can safely remove it (and its closing bracket, of course).

my ($num,$date,$time,$fw,$type,$action,$alert,$int,$dir,$proto,$src +,$dst,$service,$sport,$len,$rule) = (split /;/,$_);
You don't have to name everything. Instead, you can assign to undef if you don't need a specific value.
my (undef, undef, undef, undef, undef, undef, undef, undef, undef, +undef, undef, $dst, $service, undef, undef, undef) = split /;/; # spl +it() works on $_ if only one argument is given.
Because there are more undefs than used values, a list slice would be even better:
my ($dst, $service) = (split /;/)[11, 12];

%hash = (dest => $dst, service => $service); foreach my $key (keys %hash){ my $val = $hash{$key}; $count{$val}++; } #close foreach } #close while
There's no need to use these temporary variables %hash and $val;
Well indented code doesn't need "#close foreach" comments (unless it's a huge sub, but in that case the design was probably wrong anyway).
Because only the values of the hash are used and they're set within the same scope, there's no need for the hash at all.
I'll also use the for-modifier (for equals foreach, but is shorter) to demonstrate perl's nice syntactic features.
$count{$_}++ for $dst, $service; }

foreach my $key1 (keys %count){ print "$key1 appears $count{$key1} times\n"; } #close foreach
This can be done using map, but it might be confusing if you don't know how it works:
print map "$_ appears $count{$_} times\n", keys %count;

Please also note I have a whitespace after every comma, which in my opinion makes the source more readable.
I hope this was useful to you

As a whole:

#!/usr/bin/perl -w use strict; + my $log = './log'; my %count; open (LOG, $log) or die "Can't open $log: $!"; while (<LOG>){ my ($dst, $service) = (split /;/)[11, 12]; $count{$_}++ for $dst, $service; # Now I see it this way, I realise that # $count{$_}++ for (split /;/)[11, 12]; # would be even better :) } print map "$_ appears $count{$_} times\n", keys %count;

2;0 juerd@ouranos:~$ perl -e'undef christmas' Segmentation fault 2;139 juerd@ouranos:~$


In reply to Re: Re: Re: Another Array Problem. by Juerd
in thread Another Array Problem: comparing. by dru145

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.