Hiya Mark, Something like this should work:
#!/usr/local/bin/perl -w use strict; my $file = "file.txt"; open (READ, "<$file") || die "Can\'t open file: $!"; my @list_of_words = <READ>; close (READ) || die "Can\'t close file: $!"; my $counter = 1; foreach my $word (@list_of_words){ ++$counter; if ($word eq "Apple"){ my $counter2 = $counter; last; } } print "Found \'Apple\' in line $counter2"; exit; ### Each cycle in the foreach loop increases the value of $counter by 1. When the word is located, the loop exited due to the "last" command. So, if the word is in line number 5, $counter will have a value of 5. I hope this helps. Simon ############################################## --- Mark Mclogan <[EMAIL PROTECTED]> wrote: > > How I can know in that I number of line finds a word in a text file?. > For example, a file "file.txt" contains the following list: > > Chocolate > Cake > Cheese > Apple > orange > melon > lemon > > How I can know in that line number is the Apple word? > > Over > > MMClogan > > > _________________________________________________________________ > MSN Photos is the easiest way to share and print your photos: > http://photos.msn.com/support/worldwide.aspx > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > ===== ######################################### Warmest Regards, Simon K. Chan - [EMAIL PROTECTED] "Great spirits have always encountered violent opposition from mediocre minds." -Albert Einstein __________________________________________________ Do You Yahoo!? Send your FREE holiday greetings online! http://greetings.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]