Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Tie::File - sorting array adds empty lines

by ikegami (Patriarch)
on Sep 11, 2008 at 20:09 UTC ( [id://710723]=note: print w/replies, xml ) Need Help??


in reply to Tie::File - sorting array adds empty lines

I can replicate your results
with Perl 5.8.8 and Tie::File 0.97 and
with Perl 5.10.0 and Tie::File 0.97_02.

sort is optimized to sort in place when the source and destination are the same.

>perl -MO=Concise -e"@a = sort @a" 2>&1 | find "sort" 7 <@> sort lK/INPLACE ->8 >perl -MO=Concise -e"@b = sort @a" 2>&1 | find "sort" 7 <@> sort lK ->8

I don't know if it's a bug in Tie::File when dealing with sort's optimization or a bug in sort's optimization when dealing with tied arrays, but the bug can be avoided by avoiding the optimization:

@tied_array = map $_, sort { uc($a) cmp uc($b) } @tied_array;

Update: Better yet,

@tied_array = ((), sort {uc($a) cmp uc($b)} @tied_array);

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://710723]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-19 20:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found