Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Problem with tie (hash) and dbi?

by smferris (Beadle)
on Jun 06, 2003 at 18:00 UTC ( [id://263805]=note: print w/replies, xml ) Need Help??

in reply to Problem with tie (hash) and dbi?

Ok.. this just keeps getting more weird.. I know I'm missing something.. Given, mostly the same code, slightly commented:

#!/db01/app/perl/5.6.1/bin/perl package Test; use strict; use Data::Dumper; use DBI; sub TIEHASH { my($class)=@_; my($self)=bless {}, $class; # POSITION 1 $self; } sub FETCH { my($s,$k,$v)=@_; # POSITION 2 my $store=$s->{STORE}->{$k} ||= {}; $store->{bar}='baz'; # POSITION 3 my $dbh=DBI->connect('dbi:ExampleP:','','') or die; $store; } 1; package main; use Data::Dumper; my %h; tie %h, 'Test'; $h{a}->{'foo'}='bar'; print Dumper $h{a};

Leaving the connect at position 3 (see the comments) it doesn't work at all.. it errors as mentioned previously.. Move the connect to position 2.. no error.. but foo isn't set either.. however, the data from the query (missing in the above code) does get populated into the hash properly.. If I move the connect to position 1.. it works exactly as I intended it. Wha.. huh!? foo is set, the data from the query populates properly.. and the Dumper in main is exactly as I expect..

What don't I see? I'm guessing some sort of scope issue.. ??

Again, any help.. GREATLY appreciated!
SMF 8)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://263805]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-05-30 21:54 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.