I have experienced some strange behaviour with Tie::File.
The following code ties to the file, adds some elements, then sorts them and unties. After that, a newline is added to the file. Those newlines add up and clutter the file.
prints:#!/usr/bin/perl use strict; use warnings; use Tie::File; tie my @tied_array, 'Tie::File', 'tiefile' or die "Could not tie to t +iefile: $!"; push(@tied_array, $_) for (1..3); print "\@tied_array has " . scalar @tied_array . " elements before sor +ting\n"; @tied_array = sort {uc($a) cmp uc($b)} @tied_array; print "\@tied_array has " . scalar @tied_array . " elements after sort +ing\n"; untie @tied_array;
~/dev/perl$ perl test_tie_file.pl @tied_array has 3 elements before sorting @tied_array has 4 elements after sorting ~/dev/perl$ perl test_tie_file.pl @tied_array has 7 elements before sorting @tied_array has 8 elements after sorting ~/dev/perl$ perl test_tie_file.pl @tied_array has 11 elements before sorting @tied_array has 12 elements after sorting ~/dev/perl$ cat tiefile 1 1 1 2 2 2 3 3 3 ~/dev/perl$
In reply to Tie::File - sorting array adds empty lines by svenXY
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |