Hi All,

Can some one please look at my code ad see what I am doing wrong.

For some reason it is not working. The idea is to search the file using the
commandline argument. It is supposed to read the file and if a match is
found, it outputs to another file. If a match is not found is appends the
existing file.

Somehow my script appends to both files. Why?

commandline %./filename 4040 332
Thanks
Arvind

--------
#!/usr/bin/perl -w

$CardID1="$ARGV[0]";
$CardID2="$ARGV[1]";

$file="dat";
$tmpfile="tmp";
open(myFILE,"+<$file") || die "Can't open $file:$!\n";
open(tmpFILE,">>$tmpfile") || die "Can't open $tmpfile:$!\n";
while (<myFILE>){ #each line is assigned to $_, the default value

     if ((/$CardID1/) && (/$CardID2/)){
       print tmpFILE $_;
       $dbase=" existing record\n";
      }else {#entry does not exist, then add
        $dbase=" new entry\n";
        }
}
close(tmpFILE);
close(myFILE);

open(myFILE,">>$file") || die "Can't open $file:$!\n";
       print myFILE "$dbase";
close(myFILE);
---------
 dat file has the following entry-

4040:988:2:1:jane
4040:332:2:2:ken
4040:567:2:3:junior

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to