In a message dated 2007-8-15 23:39:42 中国标准时间, [EMAIL PROTECTED] writes:

open  (FH, “file");
@FH = <FH>;
foreach $line(@FH){
processing linebyline
}
close FH;

However, I only need certain  part of file only to be read (let say beginning
20 lines). 


 
Yes perl's builtin variable '$.' stores the line number when reading a  file.
@FH =<FH> is a bad way,it read all the file content in  memory,would consume 
your memory quickly.
For reading the first 20 lines,you may do,
 
open FH,'file' or die $!;
while(<FH>) {
    last if $. > 20;
    processing linebyline;
}
close FH;



************************************** Get a sneak peek of the all-new AOL at 
http://discover.aol.com/memed/aolcom30tour

Reply via email to