jacques has asked for the wisdom of the Perl Monks concerning the following question:
In that function, the hash gets tied and modified. After the function returns, the original hash now has new values. It goes a little something like this:
This is what the function looks like... (note that I simplified the function and everything else for demo purposes)my %hash; my $blah = function(\%hash); warn Dumper \%hash; # prints a bunch of values
Okay, everything is working as it is suppose to be. But when I put that tie() into a separate module that returns the tied hash, then the original hash is not modified. This is a problem. Here's what the function looks like when using that module.sub function { my ($hash) = @_; tie %$hash, 'Apache::Session::File', undef, { Directory => $r->dir_config('blah'), LockDirectory => $r->dir_config('blah'), }; $hash->{auth}->{user} = "jacques" }
When putting the tie() in a module, the %hash will have no values when the function returns. It never gets modified outside of the function. How can I use the modular approach and have the original hash modified?sub function { my ($hash) = @_; $hash = MyModule::tie_session(); $hash->{auth}->{user} = "jacques"; }
Here's what the module looks like:
Package MyModule; use Apache::Session::File; sub tie_session { my $hash = {}; eval { tie %$hash, 'Apache::Session::File',undef, {Directory => $r->dir_config('Blah'), LockDirectory => $r->dir_config('Blah'), }; }; return $@ if ($@); return $hash; } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: References, hashes, and tie() -- oh my
by japhy (Canon) on Jun 11, 2005 at 01:54 UTC | |
|
Re: References, hashes, and tie() -- oh my
by Limbic~Region (Chancellor) on Jun 11, 2005 at 00:08 UTC | |
by jZed (Prior) on Jun 11, 2005 at 01:13 UTC | |
by devnul (Monk) on Jun 11, 2005 at 00:28 UTC | |
by Limbic~Region (Chancellor) on Jun 11, 2005 at 00:33 UTC | |
|
Re: References, hashes, and tie() -- oh my
by jacques (Priest) on Jun 11, 2005 at 02:05 UTC |