Rob Dixon wrote:
>
use strict;
use warnings;
use Carp;
my @maillog = do {
opendir my $dh, '.' or croak "Can't open directory: $!";
grep /^maillog/, readdir $dh;
};
my @parsedmail;
foreach my $log (@maillog) {
open my $fh, $log or croak "Can't open $log: $!";
while (<$fh>) {
if (/(?:imapd|pop3d).*Log.*user/) {
push @parsedmail, $_;
last;
}
}
}
print "$_\n" foreach @parsedmail;
That is wrong. I was thinking you wanted the names of all the files that
contained the given pattern (and it doesn't even do that quite correctly). Since
you just want the matching lines printed, it can be reduced to:
foreach my $log (@maillog) {
open my $fh, $log or croak "Can't open $log: $!";
while (<$fh>) {
print if /(?:imapd|pop3d).*Log.*user/;
}
}
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/