thank you. seek did the job. by the way can this be made any better?
just want to find out in how many records string was found: my $count=0; seek $tmp_FH,0,0; while (<$tmp_FH>) { my $line=$_;chomp($line); if ($line=~m/\"$str\"/) {$count++;} #in the file $str string would be in quotes.... } ________________________________ From: Andy Bach <afb...@gmail.com> To: Rajeev Prasad <rp.ne...@yahoo.com> Cc: perl list <beginners@perl.org> Sent: Monday, August 20, 2012 2:10 PM Subject: Re: re-reading from already read file handle On Mon, Aug 20, 2012 at 2:00 PM, Rajeev Prasad <rp.ne...@yahoo.com> wrote: > is this default behaviour? how to work around this? file is big and I do not > want to keep in memory as array. so is my only option is to close and open > the file again? Yes, that's the default. "seek" lets you reset things though perldoc -f seek seek FILEHANDLE,POSITION,WHENCE Sets FILEHANDLE’s position, just like the "fseek" call of "stdio". FILEHANDLE may be an expression whose value gives the name of the filehandle. The values for WHENCE are 0 to set the new position in bytes to POSITION, 1 to set it to the current position plus POSITION, and 2 to set it to EOF plus POSITION (typically negative). For WHENCE you may use the constants "SEEK_SET", "SEEK_CUR", and "SEEK_END" (start of the file, current position, end of the file) from the Fcntl module. Returns 1 upon success, 0 otherwise. -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/