Romeo Theriault wrote:
> Hello,

Hello,

> I'm trying to match this line (or more than one) starting from 
> the words "user picard..."
> 
> 8/28/2006 1:04:41 PM: Retrieving mail from host mail.maine.edu 
> [130.111.32.22], user picard...
> 8/28/2006 1:04:45 PM: Mail retrieval failed, reason: POP3 Host did  not
> acknowlege password and returned following error: -ERR [AUTH]  Invalid
> login
> 
> 
> Using this regular expression:
> 
> user (\w+(\.\w+)?(\.\w+)?)\.\.\.\n\d{1,2}\/\d{1,2}\/\d{4} \d{1,2}:\d
> {2}:\d{2} (A|P)M: Mail retrieval failed, reason: POP3 Host did not 
> acknowlege password and returned following error: -ERR \[AUTH\]  Invalid
> login
> 
> I seem to be matching it in ActiveState's regular expression toolkit, 
> but when I try running the code it doesn't match the lines. I've 
> tracked it down to the new line character after the three dots at the 
> end of the first line. But I can't figure out how to get past it. The 
> \n don't work. I've tried using chomp and then removing the new line 
> character but it still doesn't match.
> 
> Below is my code that I'm trying to get working and can't seem to get 
> that regex. Any pointers that any has would be appreciated. Thank you.
> 
> #!/usr/bin/perl -w
> 
> use strict;
> my %saw;
> my @dup_array;
> 
> # Open the file for reading and if cannot die and give error message.
> open LOG, "c:\\Documents and Settings\\romeok\\desktop\\perl\
> \CopyofPOPconSrv.log"
>     or die "Cannot open file for reading: $!";
> 
> 
> # While the file is open read through it and remove new line characters.
> # Look for the memory variable $1 and push it into the
> # @dup_array.
> 
> while (<LOG>) {
>     if (/user (\w+(\.\w+)?(\.\w+)?)\.\.\.\n\d{1,2}\/\d{1,2}\/\d{4} \d
> {1,2}:\d{2}:\d{2} (A|P)M: Mail retrieval failed, reason: POP3 Host  did
> not acknowlege password and returned following error: -ERR \[AUTH \]
> Invalid login/) {
>     push @dup_array, $1;
>     }
> }

This may be what you want:

while ( <LOG> ) {
    if ( /user (\S+)\Q...\E$/ and my $user = $1 and
         <LOG> =~ /Mail retrieval failed, reason: POP3 Host did  not
acknowlege password and returned following error: -ERR [AUTH]  Invalid login/ ) 
{
        push @dup_array, $user;
        }
    }


> # When done close the file.
> close LOG;
> 
> # These two lines remove duplicates from the array.
> undef %saw;
> my @no_dup_array = grep(!$saw{$_}++, @dup_array);

No need to define %saw in file scope:

my @no_dup_array = do {
    my %saw;
    grep !$saw{ $_ }++, @dup_array;
    };


> # For each item in the array print it out.
> # Actually use this to send an email instead.
> foreach (@no_dup_array) { #Uses $_ by default
>     print "$_\n";
> }


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to