Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sort

Status
Not open for further replies.

tanveer91

Programmer
Nov 13, 2001
31
GB
Hi all,


Using the code below, can someone please tell how i can sort the contents in reg. no order?

I have been given this code by a friend and i'm confused!

sub missinglist () {
my $msg='';
foreach my $comp (sort keys %dealers) {
$msg.="\nmissing photographs for $dealers{$comp}->{'name'}\n\n";
foreach my $reg (keys %stock) {
my $car=$stock{$reg};
if ($car->{company} eq $comp && !defined($car->{photo})) {
$msg.=uc($reg)." $car->{make} $car->{model} $car->{stockno}\n";
} # if
} # foreach stock
} # foreach company
 
Use the numeric comparison operator '<=>' like this:

foreach my $comp (sort { $a <=> $b } keys %dealers) {
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top