Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks,

i would like to ask you for help.

Please help me to sort a referenced hash of the following structure:

$refhSmsModem looks like this:

SmsModem;Name436644301350;Thomas
SmsModem;AllowedNumbers;56456454
SmsModem;AllowedNumbers;65456456
SmsModem;AllowedNumbers;54564546
SmsModem;AllowedNumbers;98789789
SmsModem;AllowedNumbers;16515644
SmsModem;Name45645646;Thomas
SmsModem;Name54564788;Gerald
SmsModem;Name78787584;Robert
SmsModem;Name87897878;Werner
SmsModem;Name32154464;Georg
SmsModem;NotAllowedNumbers;74654564
SmsModem;SerialPort;/dev/cua00

My goal is following structure:

SmsModem;AllowedNumbers;16515644
SmsModem;AllowedNumbers;54564546
SmsModem;AllowedNumbers;56456454
SmsModem;AllowedNumbers;65456456
SmsModem;AllowedNumbers;98789789
SmsModem;Name32154464;Georg
SmsModem;Name54564788;Gerald
SmsModem;Name78787584;Robert
SmsModem;Name45645646;Thomas
SmsModem;Name87897878;Werner
SmsModem;NotAllowedNumbers;74654564
SmsModem;SerialPort;/dev/cua00

Many thanx for your help!

Clint

Replies are listed 'Best First'.
Re: How to sort referenced hash?
by GrandFather (Saint) on Sep 12, 2005 at 10:56 UTC

    Expressed like that you don't need a hash, referenced or otherwise. There must be more to the problem than you have expressed. You should show us the code that you have so far so that we know how to advise you in the context of what you actually want to achieve.

    For the problam as expressed something like:

    my @array = <DATA>; print join "", sort @array;

    would do the trick, but has obvious problems as a general solution.


    Perl is Huffman encoded by design.
Re: How to sort referenced hash?
by reasonablekeith (Deacon) on Sep 12, 2005 at 10:54 UTC
    well, your goal list is sorted by the default method provided by Perl's "sort".

    I'm not really sure what you're having difficulty with here. Is it getting the keys from your hash ref?. It would be helpful to provide a bit more detail, and perhaps a few lines of code to demonstrate what you've done that isn't working as you expect.

    ---
    my name's not Keith, and I'm not reasonable.
Re: How to sort referenced hash?
by ghenry (Vicar) on Sep 12, 2005 at 10:19 UTC

    Tried anything or written anything yet?

    Thanks.

    Walking the road to enlightenment... I found a penguin and a camel on the way.....
    Fancy a yourname@perl.me.uk? Just ask!!!
Re: How to sort referenced hash?
by Anonymous Monk on Sep 12, 2005 at 21:35 UTC
    hashes cannot be sorted