in reply to Re^5: Sorting by value??
in thread Sorting by value??
#!/usr/bin/perl use warnings; use strict; my $inFile = "UnSortReport.txt"; my $outFile = "SortedReport.txt"; open IN, "< $inFile"; open OUT, ">> $outFile"; my @not_sorted = <IN>; print OUT "|CSED Form|OrderNumber|Date|Total Documents|Total Pages +|\n"; @sorted = sort { lc($a) cmp lc($b) } @not_sorted; # alphabetic +al sort my $count = 0; foreach(@sorted) { $frmType = substr $_, 1, 4; if ($frmType eq "M729") { print OUT "$_"; $count ++; } else { print OUT "There were $count Monthly 729 runs\n"; } } $count = 0; foreach(@sorted) { $frmType = substr $_, 1, 4; if ($frmType eq "M737") { print OUT "$_"; $count ++; } else { print OUT "There were $count Monthly 737 runs\n"; } } $count = 0; foreach(@sorted) { $frmType = substr $_, 1, 4; if ($frmType eq "Q569") { print OUT "$_"; $count ++; } else { print OUT "There were $count Quarterly 569 runs\n"; } } close OUT; close IN; ##############The code Bellow looks a the SortedReport.txt and checks + for duplicate lines and removes them if any######################### +### my $file = 'SortedReport.txt'; my %seen = (); { local @ARGV = ($file); local $^I = '.bac'; while(<>) { $seen{$_}++; next if $seen{$_} > 1; print; } } print "finished processing file.\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Sorting by value??
by kennethk (Abbot) on Jun 16, 2010 at 17:29 UTC | |
by Homerhrdz (Initiate) on Jun 17, 2010 at 19:24 UTC |