#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; # use Lingua::EN::NameCase qw( nc ); #Where the files are located... my $Location = 'z:/bpermits/data2007/test/marchpermits.txt'; my $OutFile = 'z:/bpermits/data2007/test/output.txt'; # Debugging -- I don't have a Z: drive :) (and $OutFile isn't used) $Location = "./m.txt"; #Open the files...... open(PERMSIN, $Location) or die "unable to open $Location: $!"; #Read in the file, using a loop........ my @columns = qw( Permit_Number Street_Number Street_Prefix Street_Name Street_Suffix Lot Block Issue_Date Proposed_Use_Code Permission_To_Code Square_Feet Estimated_Cost Units Subdivision Zoning Contractor_Name Contractor_Add1 Contractor_Add2 Contractor_City Contractor_State Contractor_Zip Contractor_Phone1 Contractor_Phone2 Owner_Name Owner_Add1 Owner_Add2 Owner_City Owner_State Owner_Zip Owner_Phone ); # Debugging -- I don't have time to make up all those values :-/ @columns = qw( Permit_Number Street_Number Estimated_Cost ); my @data = (); while( my $line = ) { chomp( $line ); # Populate the hash %thisrecord with the column names and # the values from this line. # my @fields = split( /,/, $line ); my %thisrecord = map { $columns[$_] => $fields[$_] } ( 0 .. $#fields ); push @data, \%thisrecord; } # Debugging -- look at the data before it's sorted print Dumper(\@data), "\n"; print "Unsorted costs: "; map { print $_->{ Estimated_Cost } . ", " } @data; print "\n\n"; # Here's the sort you want! @data = sort { $a->{ Estimated_Cost } <=> $b->{ Estimated_Cost } } @data; # Debugging -- look at the data after it's sorted print Dumper(\@data), "\n"; print "Sorted costs: "; map { print $_->{ Estimated_Cost } . ", " } @data; print "\n\n";