"Alan C." wrote: > > Hello, Hello,
> This must be easy. But I've not yet enough experience with Perl's control > structures. > > perl mysort.pl infile.txt > outfile.txt > > The stack of numbers with colons below reside within infile.txt > > 120:2 > 126:2 > 13:15 > 140:3 > 14:3 > 141:3 > 14:3 > 15:11 > > My task or goal is to get each of them lines over into outfile.txt (as re > ordered lines) with all of the \d\d: (2 digits then colon) up at top of file > then with the 3 digits colon underneath sort -n infile.txt > outfile.txt > How to set up a twice through instead of only 1 pass through of the > infile.txt? (and get all of the 2digits on 1st pass, then get all of the 3 > digits on second pass)? Or, same task/goal done even yet a different way is > ok too. > > #!/perl/bin/perl -w > # mysort.pl > while ($line = <>) { > if ($line =~ m/\b\d\d(?=:)/) { > print $line; > if ($line =~ m/\b\d\d\d(?=:)/) { > print $line; > } > } > } > > That above gets/snags all the 2 digits only. There's no 3 digits to > outfile.txt #!/perl/bin/perl -w # mysort.pl print map { $_->[0] } sort { $a->[1] <=> $b->[1] or $a->[2] <=> $b->[2] } map { [ $_, split /:/ ] } <>; __END__ John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]