Ankur Gupta am Mittwoch, 10. Mai 2006 11.23: > Hi, > > Using Tie::File with recsep = "\n\n" adds two extra lines to the > original file when I iterate through the entire file. If I just change > one record then its fine. > > Below is the program > > use strict; > use warnings; > > use Tie::File; > > my @array; > tie @array, 'Tie::File', 'file', recsep => "\n\n" or die $!; > > foreach my $rec ( @array ){ > print $rec; > } > > untie @array; > > $-> diff file file.orig > 8464,8465d8463 > < > < > > Right now, I am tieing the file again without recsep and popping two > records. > > tie @array, 'Tie::File', 'file' or die $!; > pop(@array); > pop(@array); > untie @array; > > This fixes the problem but is there a better way to get around this? > > perl version is 5.8.0 and latest version of Tie::File (0.97).
Hi Ankur Gupta Your file stays unchanged only if it ends with recsep, "\n\n" in your case. (So one workaround instead of the two pops would be to make sure the input file contains this recsep at the end) This behaviour is described in perldoc Tie::File, but not enough prominent imo (and done by _fixrecs()). I think not all people expect the tied file to be altered when no write access is done. In Ankur Gupta's example, records are even added with every (un)tie. I'm not sure if this is a bug. Should the file stay unaltered if it's never accessed for writing? Should the last record even be treated specially? What do others think about this? Dani -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>