in reply to Alphabetical Order
First thing I'd do is take all those fields and stick them in a hash rather than a bunch of independent variables.
Then, rather than print it out right there -- since that would mean printing records in the order they come in -- I'll add each record's hash to an array of hashes, for sorting and printing later:while (<DATAFILEIN>) { chomp; my %record; @record{ @fields } = split /\|/;
Note that I'll have to define the @fields array before the loop, something like this:push @records, \%record; }
Now, after I've gotten all the record hashes into @records, I can sort them by company name and print them out:my @fields = qw( time company_name email member1 member1phone data time2 pictureurl password website member2 member2phone address citystatezip fax );
for ( sort { $a->{'company_name'} cmp $b->{'company_name'} } @record +s ) { print "$_->{'company_name'} and other fields here.\n" }
Another thing you might consider... If the company names are unique, store the records in a hash keyed by company_name, rather than in an array. Something like this:
Does that make sense? If you have any questions, let me know.while (<DATAFILEIN>) { chomp; my %record; @record{ @fields } = split /\|/; $records{ $record{'company_name'} } = \%record; } # this makes the sorting a bit more straightforward: for ( sort keys %records ) { my %rec = %{ $records{$_} }; print "$rec{'company_name'} and other fields here.\n" }
jdporter
...porque es dificil estar guapo y blanco.
|
|---|