5% assure discount from here only

Showing posts with label file read. Show all posts
Showing posts with label file read. Show all posts

Tuesday, July 10, 2012

(30) How to read and print the content of file, using line number?

Solution:

Sometime we need to print or show content from file on basis of line number.

Suppose we have a file, which contains 1000 of lines and we need to print the content from line number 30 to 50.

Following example will show, how can we do this :-

open FILE, "/location/filename";
while(<FILE>){
if($. > 29 && $. < 51){ # Here $. represents the line number
print $_; # Here $_ represents the content
}
}
close FILE;