in reply to Sort Problem
The sort block uses numeric comparison; it will do the right thing with the strings in your example, no matter how many digits are in the first field. If you want to sort based on some other field in each line, you'll need to build a hash with the hash key being the field you are sorting on, and the value being the other fields in each line. That means you need one loop over @DB to split each line and store it in the hash; then you need a second loop to print out the data in sorted order, and this second loop begins with something like:foreach $rec ( sort { $a <=> $b } @DB ) { chomp $rec; ($num,$name,$email,$xnumber) = split /\#/, $rec; # print and do whatever else you want... }
foreach my $key (sort keys %dbhash) { # print the data found in $dbhash{$key} }
|
|---|