Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hi
I have to find a particular keyword in file(<run>) and then truncate whatever is present after it and then seek to that position and start writing again on file.My code is as follows
$outputDir="$Location/statistic_file.xml"; open(OUTPUTFILE, '+<',$outputDir) or die "$outputDir : $!"; my $outputFileSize = -s $outputDir; if($outputFileSize != 0) { seek(CONFIRMEDOUTPUTFILE, -500, 2); my $lastChrs = <OUTPUTFILE>; my $Position = index($lastChrs, '<run>'); my $String = substr($lastChrs, $Position); $String =~ /Bytes=\"(\d+)\" Scanned=\"(\d+)\" total=\"(\d+)\"/; truncate CONFIRMEDOUTPUTFILE, $outputFileSize-length($String); seek(CONFIRMEDOUTPUTFILE, 0, 2); print CONFIRMEDOUTPUTFILE $temp; }
But it is not working.. What am I doing wrong??
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: File seek
by soonix (Chancellor) on Feb 25, 2013 at 10:49 UTC | |
|
Re: File seek
by Anonymous Monk on Feb 25, 2013 at 10:15 UTC | |
by Anonymous Monk on Feb 25, 2013 at 10:37 UTC | |
by Anonymous Monk on Feb 25, 2013 at 10:45 UTC | |
by johngg (Canon) on Feb 25, 2013 at 11:55 UTC | |
by vinoth.ree (Monsignor) on Feb 25, 2013 at 11:50 UTC |