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;
In reply to References, hashes, and tie() -- oh my by jacques
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |