Zo has asked for the wisdom of the Perl Monks concerning the following question:

Hello..again.. Well, I'm stuck and used all resources and now I'm here again for help. --objective of subroutine: to take the aba, acct, and time from a file and compare to another file. if it's not there, then print to comparing file. Comparing to this file. File looks like this:
0246801357;12345678;000425 # aba, acct, time
I am just reading the above file, if all matches, then print out to an error file that the info is already there. if doesn't match, print unmatched to the above file and set the variabe $trans_code to 'true'. when opening Tracking at beginning of program, it is opened with >> for appending. All variables are global.
sub table{ seek(TRACKING, 0, 0); while (defined($t_table = <TRACKING>)){ chomp($t_table); @trk = split(/;/, $t_table); if (($trk[0] == $aba) && ($trk[1] == $acct) && ($trk[2 +] == $time)) { print ERROR "ABA:$aba\tAccount:$acct\t$time already in +table\n"; } else { print TRACKING "$aba;$acct;$aba\n"; $trans_code = "true"; } # end else / if } # end while tracking } # end sub table
This subroutine is called in the script by &table; Is there something missing? I've tried calling with &table();, I've put the last variable initialized in a return statement -- return($trans_code_valid).. how to make it work, help please.. thanks in advance... i'm learning (atleast i used code tags in this posting!) Zo

Replies are listed 'Best First'.
Re: nonworking subroutine
by chromatic (Archbishop) on Oct 17, 2000 at 00:21 UTC
    Try eq instead of == for string comparisons.

    Update: I swear, there were alphabetical characters in the input string the first two times i read it. *sigh*. Time to answer the state of my vision poll.

      the comparisons are all numeric.. but thanks anyways.. I figured it out my brothers... I just initialized the table in the function, then did the comparisons in the main part of the script. that did the trick. thanks again... and if anyone does have any other suggestions on how to improve any of the code.. please feel free, I'm always willing to learn and listen.
        You should probably use eq anyway. If the account numbers can get long then you risk overflowing what can be stored in numeric format and having your program perform unexpectedly.
        my $f='123456789123456789'; my $g='123456789123456788'; print "g == f\n" if $g == $f; print "g eq f\n" if $g eq $f;
        produces
        g == f
        Not necessarily the result you want.