Try this...

@sortarr = sort {$a->{Classvalue} <=> $b->{Classvalue}}
(@unsortedobjectarray)


$a and $b *ARE THE OBJECTS*, not the index.

Rob

-----Original Message-----
From: Nils-Anders Persson [mailto:[EMAIL PROTECTED]
Sent: Thursday, February 27, 2003 9:14 AM
To: [EMAIL PROTECTED]
Subject: Sorting an Array with classobjects


Hello Perlgurus!

I have made a small program that creates some instances of a classobject and
puts them into an array. I want to sort this array in order of a specific
value in the class.

I was thinking of something like this but it doesn't work

@sortarr = sort byvalue (@unsortedobjectarray)
sub byvalue {
$refa = $unsortedobjectarray[$a];
$refb = $unsortedobjektarray[$b];
$refa->{Classvalue} <=> $refb->{Classvalue}
}




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to