On 8/15/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> 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;
>
>

Minor comment:
I presume there is a specific RegEx you can test for instead of
hardcoding the value "20"

Reply via email to