in reply to Structuring maillog data - hopefully simple question on arrays/hashes

Just a couple of general comments, which may or may not be useful ;)

Firstly, I don't really see the need to run through your log file more than once. Also, I think just a single hash (a HOH, actually) would suffice for your purposes. I would use the originating message ID as the key to the hash, and then have several sub-keys such as "destination_id", "status", "source_host", "destination_host", etc. And then just populate the values for each of these as you run through the log file. Once you are done, it's just a matter of iterating through your hash keys and outputting those of interest.

The second point is yes, it would be better to use a while loop to read through your log file. By using a foreach loop, you are effectively slurping the whole file into memory. Whereas a while loop will just read line by line. So something like:

while (my $line = <FH>) { chomp($line); # you probably want to do this # do whatever with contents of $line }
Hope this helps,
Darren :)
  • Comment on Re: Structuring maillog data - hopefully simple question on arrays/hashes
  • Download Code

Replies are listed 'Best First'.
Re^2: Structuring maillog data - hopefully simple question on arrays/hashes
by billie_t (Sexton) on Jun 12, 2007 at 06:52 UTC
    An HoH is one of those magical incantations I have not got the hang of yet. But after your suggesting I could just go through the log once, and use while loops in preference (I didn't know that a foreach grabs everything into memory), I managed to nut out a way of grabbing the right info at the right time (I've stuck my mucky code at the bottom of the thread). Thanks very much for your input; it was a great help.