Hi Alan , All Just in case the data structures and the sort routines intimidate you , the following hack works too :
#usage : [perl.exe \ perl] reorder.pl infilepath reorderedOutFilePath open INFILE, @ARGV[0] or print "can't open INFILE!" ; open OUTFILE, ">@ARGV[1]" or print "can't create OUTFILE!" ; while(<INFILE>) { if(/^[0-9]{2}:/) { print OUTFILE "$_"; } else { push @temp , $_ ; } } close INFILE; foreach $element(@temp) { print OUTFILE "$element"; } close OUTFILE; Just copy paste the above program and it'll do the trick :) -aman. -----Original Message----- From: Alan C. [mailto:acummingAT@;cwnetDOT.com] Sent: Friday, November 08, 2002 2:53 PM To: [EMAIL PROTECTED] Subject: sort two patterns, control structure help needed 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 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 -- Thanks. Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]