Charles K. Clarkson wrote:
: I've been thinking about it an wondering if it needs to be this : complex. Can't I just create a hash (With the message ID as the key) : and the line as data? I tried:
Only if the message ids are unique. I have no idea what a mail log looks like, so I don't know if they are unique.
my %msgids; while ( <MAILLOG> ) { if ( /$email/ && /([A-Z1-9]{8})/ { $msgids{$1} = $_; } }
OK, I've read about refrences and have come up with the following:
#!/usr/bin/perl
use warnings; use Data::Dumper 'Dumper';
print "Please enter an e-mail address: "; chomp($email = <STDIN>);
open MAILLOG, "/var/log/maillog";
my %msgids; while (<MAILLOG>) { if (/$email/ and /([A-Z1-9]{8})/) { %msgids = ("$1" => $msgarray[$_]); } }
print Dumper \%msgids;
The problem is, there is more than one line of text I need to dump into the anonymous array. Although the message ID's are unique in that each message will have it's own one, it will appear in the log about four times with four lines of information. My hash will have the message ID which refrences the array but the array will only contain the last line matched.
What I'd like, is for the array to have all four lines in rather than overwriting each time a new match is found. Is this possible with the kind of approach we are looking at?
Nick
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>