Jose Nyimi wrote:
> 
>>-----Message d'origine-----
>>De : John W. Krahn [mailto:[EMAIL PROTECTED] 
>>Envoyé : jeudi 22 septembre 2005 23:26
>>À : Perl Beginners
>>Objet : Re: Is it possible to force a particular order in a hash?
>>
>>
>>Dave Adams wrote:
>>
>>>I have a hash that I need to use later and display some values in a 
>>>particular order.  Perl comes up with its own way of 
>>
>>ordering it but I 
>>
>>>am wondering if I can instruct perl to have it listed in 
>>
>>the way that 
>>
>>>I want.
>>
>>You could store the ordered keys in a separate array or you 
>>could use the Tie::IxHash module.
> 
> 
> I'm wondering if Tie::IxHash is suitable here.
> Indeed, from the module doc i'm reading the following:
> 
> "This Perl module implements Perl hashes that preserve
> the order in which the hash elements were added".
> 
> It seems that the OP here wants to "customize" the order,
> not only preserve the order in which elements were added during hash
> contruction.
>

>From the perldoc:

"Reorder

    This method can be used to manipulate the internal order of the
IxHash elements by supplying a list of keys in the desired order. Note
however, that any IxHash elements whose keys are not in the list will be
removed from the IxHash."

Based on that and the push,pop,shift,unshift,splice and replace methods
you should be able to simulate just about any reordering operation.

http://danconia.org

> Input order: AUTHOR LANGUAGE TITLE
> Desired output order: TITLE AUTHOR LANGUAGE
> 
> Suggestion from Waldemar Jankowski looks promizing ...
> 
> Regards,
> José.
> 
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to