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

RE: Compare script fails (Solved!)

Thread Next
From:
Michael Weber
Date:
December 6, 2002 09:27
Subject:
RE: Compare script fails (Solved!)
Message ID:
sdf08972.081@mail-2.alliednational.com
It was a trailing space in $_  that was getting me.  I changed a chomp
to a chop and it now finds the string.

Thanx for the tip, and the code!

-Michael

>>> "Patel, SamirX K" <samirx.k.patel@intel.com> 12/05/02 05:08PM >>>
Could there be extra, non-visible characters attached to the subject
coming
back?  You might want to try using a regular expression to do the
comparison.  It'll give you more control to pass or ignore stuff.

Something the following will ignore extra leading or trailing
characters,
and ignore case changes from the original:

if ($_ =~ /$LOOKFOR/i ) {
  $FOUND = 1;
}

Hope this helps!

Samir


-----Original Message-----
From: Michael Weber [mailto:mweber@alliednational.com] 
Sent: Thursday, December 05, 2002 12:03 PM
To: beginners@perl.org 
Subject: Compare script fails

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


-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org 
For additional commands, e-mail: beginners-help@perl.org

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