in reply to sorting numbers

You have some issues. First, if you read the files form @ARGV, unless I am mistaken, you won't be able to tell when one file ends and another one starts. Do you really want to create something that sorts large groups of files together? If the files are relatively small, and if I read your requirements correctly, you could try something like the following (untested).

foreach my $file ( @files ) { local *FH; open FH, "+< $file" or die "Cannot open $file for updating: $!"; my @data = <FH>; @data = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, get_num( $_ ) ] } @data; seek FH, 0, 0 or die "Cannot seek to start of $file: $!"; print FH @data; close FH; } sub get_num { my $line = shift; my ($num)= $line =~ /t=(\d*)/; # you may need to play with this $num ||= 0; # assign a default to supress "not numeric" errors return $num; }

What that does: for each file, open in update mode. Read the lines. Sort them with the Schwartzian Transform. seek to beginning of file, print the lines, close the file and move on to the next. I didn't call truncate as file lengths should be the same.

Warning: As this is untested and I don't know if this really meets your needs, be sure to back up your files first. Also, take off the -i switch with this technique.

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.