Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A question about eq 1

Status
Not open for further replies.

LuckyKoen

Programmer
Feb 14, 2005
57
BE
I have a file with a few lines of text in it. I read each line and put them in an array named @lines :

open FILE, "file.txt";
while(<FILE>) { push @lines,$_; }
close FILE;

Then I want to look for a certain line named "Hello".

my $text = "Hello";
foreach $line (in @lines) {
if ( $text eq $line ) {
print "Hello was found in the document";
}
}

For some reason $text eq $line doesn't work even tho they both contain "Hello".

Can anyone help me with this ?
 
Try ...
Code:
if ( $line =~ /Hello/) {


``The wise man doesn't give the right answers,
he poses the right questions.''
TIMTOWTDI
 
I always have problems with line endings in instances like this this

chomp $line;
 
You're right about the linefeeds. A simple chomp $line before the if took care of my problem. Thanks for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top