develooper Front page | perl.perl5.porters | Postings from January 2003

[perl #20616] Tie::IxHash doc error.

Thread Next
Beckett Richard-qswi266
January 30, 2003 08:02
[perl #20616] Tie::IxHash doc error.
Message ID:
# New Ticket Created by  Beckett Richard-qswi266 
# Please include the string:  [perl #20616]
# in the subject line of all future correspondence about this issue. 
# <URL: >


I have found an error in the documentation with Tie::IxHash.

Perldoc returns:

  How can I make my hash remember the order I put elements into it?

            Use the Tie::IxHash from CPAN.

                use Tie::IxHash;
                tie(%myhash, Tie::IxHash);
                for ($i=0; $i<20; $i++) {
                    $myhash{$i} = 2*$i;
                @keys = keys %myhash;
                # @keys = (0,1,2,3,...)

Using Tie like this will cause an error with use strict. The line:
tie(%myhash, Tie::IxHash);
should be:
tie(%myhash, 'Tie::IxHash');

otherwise you will get a 'bareword' error.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About