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

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

Thread Next
From:
Beckett Richard-qswi266
Date:
January 30, 2003 08:02
Subject:
[perl #20616] Tie::IxHash doc error.
Message ID:
rt-20616-49904.16.891027432675@bugs6.perl.org
# 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: http://rt.perl.org/rt2/Ticket/Display.html?id=20616 >


Hello,

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.

R.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About