I think you missed my point on why Tie::File would be good for you. I see you found your solution already, so this is after the fact, but here you go anyway.
Tie::File allows you to take a large file and treat it as an array without pulling the entire file into memory. If I understand you correctly you need to make new files from the randomized lines of some really huge file, without messing up the order of the original huge file.
what could be easier than an array for this? As soon as you attach to your large file with Tie:File you instanly know the total number of lines. It is trivial to have perl return you a random number in between 0 and the total number of lines you have. Then simply write that line to your new file, and keep track of the line number(array element) because you don't want to use it again. Now the trick is in optimizing your random number generator function to return a "unique" random number each time, cause you don't want to sit there waiting for a line you haven't used yet, especially as over time the number of lines used out numbers the unused ones.
My suggestion is that you create your self a "Random Order List". Since you know the total number of lines you effectively have a sequence of numbers. All you really want to do is jumble that sequence up then write out the now random list "in order", this is typically called a "shuffle". Lets look at some code
# @lines is the old unshuffled array(list of indexes to your Tie::Fil
+e array)
@lines = 0..51;
#for you the sequence would be 1..(scalar @YourTieArray)
@shuffled = (); # an empty array
$numlines = 52; #scalar @yourTieArray again
while ($numlines > 0) {
push(@shuffled, splice(@lines, (rand $numlines), 1));
$numcards--;
}
# @shuffled contains the shuffled lines, @lines is empty
now my thinking says that shuffling a list of intergers, even if that list is big, will take less memory, and less time than having every line reprinted with a random token in front of it, because Once you have your shuffled list of array indexes all you have to do is loop through it and print the corresponding line from your Tie::File array.
A discussion of shuffling algorithms that contributed to my comment can be found here:
http://c2.com/cgi/wiki?LinearShuffle
if you read this let me know if it made a time improvement or not.
Ketema