Perl Question (programming code)?

ninjakidd

New member
For some reason when it searches reads every other line.... i can't figure out why:

#!/usr/local/bin/perl



print "type word to search for: ";
$line=<STDIN>;

print "The file reads:\n";
open (MYFILE, 'test.txt');
while (<MYFILE>)
{
chomp;
print "$_\n";


}
close (MYFILE);



open (MYFILE, 'test.txt');
while (<MYFILE>)
{
chomp;
if (<MYFILE> =~ /$line/)
{
print "$_";
print ", It matches\n";
}
else
{
print "$_";
print ", It doesn't match\n";
}


}
 
Back
Top