require 5;
sub get_line_num
{
my ($file_name, $string_to_look_for) = @_;
my $line_num = -1;
open ( MYFILE, $file_name ) or die "Error opening file '$file_name'.
Reason is <$!>";
while ( <MYFILE> )
{
if ( /$string_to_look_for/i ) { $line_num = $.; last; }
}
close( MYFILE );
return $line_num;
}
my $num = get_line_num( 'file.txt', 'apple' );
print "The word 'apple' was found in line number '$num'\n";
---------------------
[Sathish]
-----Original Message-----
From: Mark Mclogan [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 28, 2001 1:37 PM
To: [EMAIL PROTECTED]
Subject: Question!! number of line....
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]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]