in reply to Proper way of passing around tie'd variable
Somni is correct about using a reference to pass the tied hash around. In the code you have, you'd return \%hash inside hash_init. Outside, you'd say my $hash_ref = hash_init() and then $hash_ref->{$id} to access some part of it.
That aside, I notice you flock after the hash has been tied. I think it would be better to get a lock on something before the hash is tied. You may want to use a separate lock file for that purpose. I don't know for a fact that what you're doing now leaves room for a problem, but it looks suspicious to me.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Proper way of passing around tie'd variable
by graffitici (Novice) on Jan 07, 2008 at 12:42 UTC | |
by kyle (Abbot) on Jan 07, 2008 at 15:37 UTC | |
by graffitici (Novice) on Jan 07, 2008 at 18:04 UTC | |
by kyle (Abbot) on Jan 07, 2008 at 18:20 UTC |