hi perlmonks, I am trying to write a perl module which has to use CPAN module tie::hash this is the first time am using this module and am not understanding how to tie hash and how to print the stored key and its values. Here is my code
#!/vol/perl/5.8/bin/perl use lib "/vol/perl/5.8/DBD/oracle9.2/lib/site_perl/5.8.1/sun4-solaris" +; $key="num"; $val=12; package NewHash; require Tie::Hash; use Carp; use vars qw(@ISA); @ISA = qw(Tie::StdHash); sub TIEHASH { my $class = shift; print $class; my %hash; @hash{@_} = (undef) x @_; return bless \%hash, $class; } sub STORE { my ($self, $key, $val) = @_; print $key,$val; if (exists $self->{$key}) { print $key,$val; $self->{$key} = $val; # croak "invalid key [$key] in hash\n"; return; } else{ print hhh; $self->{$key} = $val;} return; } sub FETCH { my $self = shift; my $key = shift; my $is_re = (ref $key eq 'Regexp'); return $self->{$key} if !$is_re && exists $self->{$key}; $key = qr/$key/ unless $is_re; /$key/ and return $self->{$_} for keys %$self; return; } package main; { my $b=new; $b->TIEHASH(NewHash); $a=NewHash->STORE('num',12); print "Package Type: ", ref($a), "\n"; print "$self->{$key}"; }
so far i have done this but when i run it its not showing any results. And also I wanted to see those key and its values and use those values for some other purpose. Guys could any one please help me that would be really great. Thanks.

In reply to using Tie::Hash CPAN module by sudeep

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.