Use of Tie::IxHash

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Use of Tie::IxHash

Smruti Mohanty
#!/usr/bin/perl -w
use strict;
use Tie::IxHash;

my $score_for = {
    jim => 89,
    mary =>73,
    alice => 100,
    bob =>83,
    };

tie %$score_for,"Tie::IxHash";

print %$score_for;

Why it doesnot print any values??
Reply | Threaded
Open this post in threaded view
|

Re: Use of Tie::IxHash

Guru
Administrator
During Tie'ing of  a hash, first declare the variable, and then tie it, and then populate the data. This sequence should be maintained. For example:

my %h1;
tie %h1, "Tie::IxHash";
%h1 = (
    jim => 89,
    mary =>73,
    alice => 100,
    bob =>83,
    );
print %h1;


First decalred using my. And then tied. And then populated. Now, on printing , it will show the order in which it is inserted.

Reply | Threaded
Open this post in threaded view
|

Re: Use of Tie::IxHash

Smruti Mohanty
Thanks. Its working.