http://www.perlmonks.org?node_id=1020483

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??