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)
In reply to Re: Problem with tie (hash) and dbi?
by smferris
in thread Problem with tie (hash) and dbi?
by smferris
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |