I'm trying to create a hash that preserves the order that the keys are added. Under section "Create a hash and preserve the add-order" of this page, it gives a snippet that modifies a hash so when you do keys
it returns the keys in the order that you inserted them into the hash.
When I do the following snippet:
use strict;
our %foo;
use Tie::IxHash;
tie (%foo, Tie::IxHash);
It fails with:
Bareword "Tie::IxHash" not allowed while "strict subs" in use at /nfs/pdx/home/rbroger1/tmp.pl line 4.
Execution of /nfs/pdx/home/rbroger1/tmp.pl aborted due to compilation errors.
How can I get Tie::IxHash to work when use strict
is on?
dsolimano's Example worked.
use strict;
our %foo;
use Tie::IxHash;
tie (%foo, "Tie::IxHash");
$foo{c} = 3;
$foo{b} = 2;
$foo{a} = 1;
print keys(%foo);
prints:
cba
without the tie...Tie::IxHash
line it is
cab