in reply to Re: Complex hash sorting
in thread Complex hash sorting

sulfericacid,
I tried something similar once. I reordered the data and then just sorted the string.

However, the problem is that you have to sort ASCII which means that 999 is greater than 1000. The next thing I did was to sprintf my data so that I was comparing 0999 to 1000. That worked. That didn't really sit well though.

It seems to be a lot of mess. Then I discovered LoLs and HoLs and other complex data types. They make it much easier so I'd go with any of the methods below.

Personally I'd store the data as a LoH, but that's just me.

my @data = ( { name => 'Bill Nye', age => 39, town => 'Somewhere in Cali', state => 'Cali', zip => '12345' }, { name => 'Homer Simpson', age => 36, town => 'Springfield', state => undef, zip => '23456' }, { name => 'Barney Rubble', age => 31, town => 'Bedrock', state => 'Cartoon Location', zip => '3456' }, ); print Dumper( sort { $a->{name} cmp $b->{name} } @data );
Other monks will probably tell you that the above is not a good thing because you're storing your hash keys over and over again. However I think it makes it much easier to track your data. It would, of course, be possible to create your own data structure parsing module that had objects and methods for creating, editing and deleting data but there's a ton already out there.