I would reorganize your array of hashes, such that the numbers were hash elements with a fixed keyname,that would make the sorting simpler, I think. Otherwise you have to sort the keys of each each hash in each array element. And because you have multiple keys, some of which are words, you'd only want to sort the keys that you were able to pass off as numbers... which would require some kind of funky stuff that makes me cringe. :)
What if you organized your hash like such?
@Aname=(
{
keynum => 200,
keyname => 'hello',
name =>'akshay'
},
{
keynum => 100,
keyname => 'world',
name =>'india'
},
{
keynum => 150,
keyname => 'great',
name =>'ahm'
},
);
Then, to sort @Aname by the keynum field, you'd only need to do this:
my @sortedAname = sort {$a->{keynum} <=> $b->{keynum}} (@Aname);
Anyhoo... that's what I'd do to simplify the sorting...
--Ray
PS. Also you don't want to assign @Aname with [], that means you're assigning An array of one element, which is a reference to an array. You want to assign the @array using () (list of actual values, not a reference to one). (Corrected in my code above...) |