Help with sorting...

J

Joe Trubisz

Hi...

I have something like this:

$rec = {};
$rec->{a} = 1;
$rec->{b} = 4;
$D{$rec->{a}}=$rec;
$rec = {};
$rec->{a} = 2;
$rec->{b} = 1;
$D{$rec->{a}}=$rec;
$rec = {};
$rec->{a} = 3;
$rec->{b} = 3;
$D{$rec->{a}}=$rec;

What I want to do is sort D based on the value of b.

Can someone explain to me what the sort command should look like?
I'm stumped!

TIA,
Joe
 
J

Joe Smith

Joe said:
$rec = {};
$rec->{a} = 1;
$rec->{b} = 4;
$D{$rec->{a}}=$rec;
$rec = {};
$rec->{a} = 2;
$rec->{b} = 1;
$D{$rec->{a}}=$rec;
$rec = {};
$rec->{a} = 3;
$rec->{b} = 3;
$D{$rec->{a}}=$rec;

What I want to do is sort D based on the value of b.

print "$D{$_}{a} $D{$_}{b}\n" for sort {$D{$a}{b} cmp $D{$b}{b}} keys %D;

-Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top