in reply to array of arrays of hashes

A starting point might be something like this:
#!/usr/bin/perl use strict; use Sort::Key::IPv4 qw(ipv4sort); open(TEXT,"dump.txt")or die("Text not found"); my %packets; while (<TEXT>) { if ( /IP\s+(\d+\.\d+\.\d+\.\d+)(\.(\d+))?\s+>\s+(\d+\.\d+\.\d+\.\d++ +)(\.(\d+))?\:\s+(\w+)/ ) { my ($srcip, $srcport, $dstip, $dstport, $proto) = ($1, $3, $4, $6, + $7); printf "%16s [%5d] --> %16s [%5d] (%s)\n", $srcip, $srcport, $dsti +p, $dstport, lc($proto); if ($srcport == $dstport) { # one IP to another on the same port... $packets{$srcport}{$srcip}{$dstip}++ } } } foreach my $port (sort { $a <=> $b } keys %packets) { # ports sorted ascending foreach my $srcip ( ipv4sort keys %{$packets{$port}}) { # source IPs sorted ascending foreach my $dstip ( ipv4sort keys %{$packets{$port}{$srcip}}) { # dest IPs sorted ascending print "On port $port, from $srcip to $dstip, there were $packe +ts{$port}{$srcip}{$dstip} packets\n"; } } } }

Also, you should read about the (?:pattern) in perlre - there's no need to capture in your regex anything you don't want.

Replies are listed 'Best First'.
Re^2: array of arrays of hashes
by cotarelo (Initiate) on Nov 17, 2009 at 10:05 UTC
    Thank you very much for your answer, it clarified me the method and also it make me think it is going to be complicated if I continue this way. I think I will better use pcap library.