PDA

Click to See Complete Forum and Search --> : error in my perl code


nmretd
Oct 16th, 2001, 11:03 AM
I have the following code:

while (<INFILE> ) {
print OUTFILE;
}

The above code reads every line in my INFILE and writes it to the OUTFILE and works fine, but when I change it to the following it doesn't write anything to my OUTFILE ?

while (<INFILE> ) {
if ($_ eq "yes") {
print "$_";
print OUTFILE;
}
}

I only want to write those records to my outfile where the record ($_) = yes.

progressive
Oct 17th, 2001, 06:02 AM
to print to the outfile you need to do this!

print OUTFILE $_;

JoshT
Oct 17th, 2001, 07:05 AM
Actually the following lines should be equivalent:

print OUTFILE $_;
print OUTFILE;

This being Perl, if you wanted to write a file to std out:
while (<INFILE> ) {
print;
}