473,396 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

how do i tie a reference to a hash

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.
Jul 19 '05 #1
2 3590
In article <Lg****************@twister.socal.rr.com>, pillbug
<xx*******@socal.rr.com> 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.
Jul 19 '05 #2
pillbug <xx*******@socal.rr.com> 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
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: John Reese | last post by:
def uselessHash(filename): fp= open(filename) hash= 0 for line in fp: hash ^= hash(line.strip()) fp.close() # do I need this or is fp closed by ref count? return hash Consider the function...
3
by: Kristofer Pettijohn | last post by:
I'm defining a hash as follows: my $HASH = ( 'key1' => ( 'sub1' => 'key1value1', 'sub2' => 'key1value2' ), 'key2' => ( 'sub1' => 'key2value1', 'sub2' => 'key2value2')
2
by: Alexander Stippler | last post by:
Hi, I've got a question concerning iterators and STL. Why does the compiler warn, that function dummy in the following example returns a reference to a local temporary? In my understanding, it...
26
by: Dave Hammond | last post by:
In document "A.html" I have defined a function and within the document body have included an IFRAME element who's source is document "B.html". In document "B.html" I am trying to call the function...
5
by: Fernando Cacciola | last post by:
Hi, I need to produce an ID number that uniquely identifies a given object instance. (If the object is a boxed value, well, it won't really matter, but for _shared_ reference-types I really...
0
by: mnmnm1951 | last post by:
I am working with Sharepoint Services and am trying to add the fileversion Metadata to the Versions.aspx page using the example from the SDK. I have not done much with hashtables but it all looks...
4
by: Bo Peng | last post by:
Dear list, I am looking for a way to store a large amount of unique sequences that will be accessed by objects. The most important operations are: 1. Direct access to the sequences (from...
7
numberwhun
by: numberwhun | last post by:
Hello all! I am working on trying to figure out how to print out a hash of hashes. How the hash in the code is defined below is very similar to how the hash is defined in the script I am...
0
by: AK | last post by:
Hello, I need to do the following with an xml document which has a list of assets: 1. Hash the assets 2. Hash the element describing the assets 3. Create a digital signature (using X.509...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.