in reply to Re: using Tie::Hash CPAN module
in thread using Tie::Hash CPAN module

hi, thanks for ur reply, I almost got it but here in this example which one is the hash and key and its corresponding values can we do without using IO::file and FH because here i have some values which are stored in an array and have to store those values to a key and also the important thing is am getting values dynamically at run time so for this first I have to chech whether the key exists or not if exists replace those values with the existed values. For this thing, here am not understanding how to do this.  here we have sub functions store, delete, fetch how to pass a key and values to those functions so that it stores the  values to that key and use that key for some other purpose. I have tried this am not getting it. Thanks.

Replies are listed 'Best First'.
Re^3: using Tie::Hash CPAN module
by jeanluca (Deacon) on Feb 25, 2008 at 16:33 UTC
    You should really read Tie::Hash
    Anyway, to give you a start here is an example:
    #! /usr/bin/perl -l use strict; use warnings ; package Remember; use strict; use warnings; sub TIEHASH { my $class = shift ; return bless {}, $class; } sub STORE { my ( $self, $key, $value) = @_ ; $self->{$key}= $value ; } sub FETCH { my ( $self, $key) = @_ ; return $self->{$key} ; } package main; my %fred; tie %fred, 'Remember' ; $fred{'abc'} = 'xyz' ; print "$fred{'abc'}";