Avatar of Marketing_Insists
Marketing_Insists
 asked on

sort hash numerically in natural order

I need to sort the below hash build numericaly by it's keys,

I wouldn't want:
  1, z49535L10.txt, 24.7413310185185
  10, test.avi, 24.5892824074074
  100, Copy.7z, 24.5827546296296
  2, here.avi, 24.5753703703704
  20, z42034L10.txt, 24.7494328703704

  but, rather, the correct counting order.

#current
chdir('\temp');
opendir(DIR,'\temp');
@files= readdir(DIR); 

$count=1;
for (@files) {

	$daysold  = -M $_;
	$hash{$count}="$_, $daysold";
	$count++;

}

# sort keys numerically?
while ( ($key, $value1, $value2) =  each( %hash)) {
     print "$key, $value1, $value2\n";
}

Open in new window

Perl

Avatar of undefined
Last Comment
Marketing_Insists

8/22/2022 - Mon
Marketing_Insists

ASKER
update:
I just realized an error in my thinking - I'm trying to create a hash whose keys have multiple values - I did not do so correctly in the mid part of the code.

I need to be shown the correct way to make a hash whose keys have multiple values AND sort it in correct order.
ASKER CERTIFIED SOLUTION
wilcoxon

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Marketing_Insists

ASKER
excellent thanks!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy