develooper Front page | perl.beginners | Postings from December 2002

Compare script fails

Thread Next
From:
Michael Weber
Date:
December 5, 2002 12:04
Subject:
Compare script fails
Message ID:
sdef5cb8.090@mail-2.alliednational.com
I am writing a script to check email functionality by sending a test
message to an account that forwards it back to a pop account.  I cannot
seem to get the script to match the expected subject lines with what was
received.  No matter what I do, it never shows a match.

Any ideas?

Here's the subroutine, output is below.

sub check_expected {
# This subroutine expects an array, @subjects, to contain zero or more
# subject lines from the messages retrieved from the bounced email pop
# account, and a file in /usr/local/netchecker/database/expected_mail
# that contains the unique subjects that were sent.
# The fourth piece of the subject is the account # that is being
tested.
# If the expected subject is not found in the returned emails, we save
# the failed account #s in /usr/local/netchecker/database/failed_mail
# which, when this script ends, is used by the calling shell script
# to run /usr/local/netchecker/<account#>/scripts/email_failure
scripts.

# Debug lines


        open (FAILURES, ">>
/usr/local/netchecker/database/failed_mail");
        open (EXPECTED,
"/usr/local/netchecker/database/expected_mail");
        print LOGFILE "check_expected  Entering while loop. \n";

        while ( <EXPECTED> ) {
                chomp;
                chomp;

print LOGFILE "Time is $hour:$min \n";
print LOGFILE "In while loop, expecting $_. \n";

                $FOUND = 0 ;
                chomp;
                $LOOKFOR = "$_";

                foreach (@subjects) {

print LOGFILE "Looking for $LOOKFOR in $_ \n";
print LOGFILE "Index is ", index( $_, $LOOKFOR ), "\n";

$NEWLOOKFOR = substr( $LOOKFOR, -8);
print LOGFILE "New Looking for $NEWLOOKFOR in $_ \n";


                        $FOUND = index( $_, $LOOKFOR );

# This didn't work either.
#                       if ( index( $_, $LOOKFOR ) >= 0 ) {
#                       $FOUND = 1;
#                       }

print LOGFILE "In foreach loop. Subject = $_  Found = $FOUND \n";

                }

        }

        close EXPECTED;
        close FAILURES;
        close LOGFILE;
}



Here's the log file output:

check_expected  Entering while loop.
Time is 19:55
In while loop, expecting 5_13_45_10001_7947 .
Looking for 5_13_45_10001_7947  in Subject: 5_13_45_10001_7947
Index is -1
New Looking for 01_7947  in Subject: 5_13_45_10001_7947
In foreach loop. Subject = Subject: 5_13_45_10001_7947  Found = -1


Thanx!

-Michael


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About