Hi Mohapatra,

The idea of seek after while loop worked fine. Thanks for your help.

Regards,
Ganesh


TapasranjanMohapatra wrote:


-----Original Message----- From: N. Ganesh Babu [mailto:[EMAIL PROTECTED] Sent: Mon 5/9/2005 10:27 AM To: Perl Beginners List Subject: seek(FH, 0,0) not working

Dear All,

In the attached file, the date is present in the last line. My requirement is to capture the date and fill it in the date field from the line 1. after capturing the date through regular expression I am using seek(FH,0,0) to goto the beginning of the file. But it has no effect.

My code is like this.

while($line=<FH>)
{
if($line=~m/Printed on Sat ([a-z]{3}\s*\d{1,2}\s*\d{4})/i)
{
   $date=$1;
}
seek(FH,0,0)
$line=~s/\|\d{3}.................$date.............;
}

But this code is not giving the required result. Please help me in solving this problem.

Regards,
Ganesh


Ganesh, The substitution string is not proper. What you want to do? Just printing to STDOUT or writing to the file itself? If writing to file Have you opened the file for writing also?
If you dont need to process other lines of file, you should break from while loop and after that do a seek.
HTH
tapas




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to