Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > how do i tie a reference to a hash

Reply
Thread Tools

how do i tie a reference to a hash

 
 
pillbug
Guest
Posts: n/a
 
      02-07-2004
Hi,

I'm trying to tie a hash that is returned from a DBI
method called fetchrow_hashref. All I want to do is
override the FETCH method to validate my key names.

But fetchrow_hashref returns a reference to a hash, not a hash, and tie
seems to want a hash. Or maybe I want to tie it as a scalar?

How can I do this? I'm sort of new to perl.


 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      02-12-2004
In article <LgXUb.9525$(E-Mail Removed)>, pillbug
<(E-Mail Removed)> wrote:

> Hi,
>
> I'm trying to tie a hash that is returned from a DBI
> method called fetchrow_hashref. All I want to do is
> override the FETCH method to validate my key names.
>
> But fetchrow_hashref returns a reference to a hash, not a hash, and tie
> seems to want a hash. Or maybe I want to tie it as a scalar?
>
> How can I do this? I'm sort of new to perl.
>
>


Why don't you make a hash copy:

my $hash_ref = fetchrow_hashref(...);
my %hash = %{$hash_ref}

and tie %hash ?

If you are new to perl, why are you trying to tie hash references? I
programmed in Perl for 10 years and have yet to use Tied variables.

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 
Reply With Quote
 
 
 
 
thumb_42@yahoo.com
Guest
Posts: n/a
 
      02-16-2004
pillbug <(E-Mail Removed)> wrote:
> Hi,
>
> I'm trying to tie a hash that is returned from a DBI
> method called fetchrow_hashref. All I want to do is
> override the FETCH method to validate my key names.
>
> But fetchrow_hashref returns a reference to a hash, not a hash, and tie
> seems to want a hash. Or maybe I want to tie it as a scalar?
>
> How can I do this? I'm sort of new to perl.


There are probably several ways to do this...

One is to pass the reference as a parameter to TIEHASH, then use the
underlying reference to store/fetch things.

The other, (if this is what you want) is to dereference the hash prior
to tie():

tie %{$my_hash_ref} ...

Jamie
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
tie() with DB_File not tie()ing ? botfood Perl Misc 23 04-26-2006 01:59 AM
Tie a file to a hash SpecialK Perl 1 02-19-2004 07:04 PM
Tie a large file to a Hash SpecialK Perl 0 02-19-2004 05:28 PM
Using Tie::IxHash order a hash reference Darius Perl Misc 10 02-12-2004 11:16 AM



Advertisments