> 
> Benjamin Walkenhorst wrote:
> 
> >Hello everybody,
> >
> >I've written a perl-module that stores some settings in a DBM-hash.
> >Currently, the module checks if certain keys have defined values in the
> >hash and if so, it copies the values belonging to those keys to the
> >corresponding variables. 
> >These variables are filled with default values before, so they work even
> >if no such value is given in the hash.
> >
> >What I would like to do now: Iterate over the keys in the DBM-hash and
> >look if a local variable of the same name exists; if so, copy the value
> >from the hash to the corresponding local variable.
> >
> My initial idea is this (assuming you're talking about identity
between local variable name and hash key name):
> 
> for (sort keys %dbm_hash)
>     if (defined $$_) {
>         $$_ = $dbm_hash{$_};
>     }
> 
> Since there is no hard reference in $_, the dereferencing should be
treated as a symbolic reference.
> 

But lets not go there first. What is with all of the copying in and out
of hashes?  What is the point? Generally you shouldn't need to do this
type of thing, it usually indicates a problem elsewhere.  A hash is
usually a more useful data structure so pulling single values out and
munging a bunch of scalar variables *usually* isn't the way you want to
go about it.... so what are you really doing?  Why don't you want to
work with the values while they are in the %dbm_hash?

http://danconia.org



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to