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

RE: Compare script fails (Solved!)

Thread Next
Michael Weber
December 6, 2002 09:27
RE: Compare script fails (Solved!)
Message ID:
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!


>>> "Patel, SamirX K" <> 12/05/02 05:08PM >>>
Could there be extra, non-visible characters attached to the subject
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
and ignore case changes from the original:

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

Hope this helps!


-----Original Message-----
From: Michael Weber [] 
Sent: Thursday, December 05, 2002 12:03 PM
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
seem to get the script to match the expected subject lines with what
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
# 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

# Debug lines

        open (FAILURES, ">>
        open (EXPECTED,
        print LOGFILE "check_expected  Entering while loop. \n";

        while ( <EXPECTED> ) {

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

                $FOUND = 0 ;
                $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



To unsubscribe, e-mail: 
For additional commands, e-mail:

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About