Re: Check names of variables

From: Wiggins D Anconia (wiggins_at_danconia.org)
Date: 02/11/04


Date: Wed, 11 Feb 2004 07:20:45 -0700
To: Jan Eden <lists@jan-eden.de>, Benjamin Walkenhorst <krylon@gmx.net>,   beginners@perl.org


>
> 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



Relevant Pages

  • Re: Suggestion for an AES Based Hash Function
    ... amateurs posting here seem to favour cyphers, I go for hash functions. ... Rather than trying to use a strong one-way compression function would ... I have used a fixed set of keys in two places. ... preferred to have the first round keys fixed and to start deriving ...
    (sci.crypt)
  • Suggestion for an AES Based Hash Function
    ... amateurs posting here seem to favour cyphers, I go for hash functions. ... Rather than trying to use a strong one-way compression function would ... The round function ... I have used a fixed set of keys in two places. ...
    (sci.crypt)
  • Re: sort unique
    ... given that a hash table is not ... IMO if the vendor's algorithm does something "obvious", ... function to eliminate keys that hash to the same bucket per some ... strings of random lengths, and two strings are ...
    (comp.lang.lisp)
  • Re: My First C# (warning - long post)
    ... defined as a COBOL structure of 8192 bytes (this is for ... Hashtables use two objects, one is a 'key' and the other a 'value'. ... but is for storing keys only. ... // Add some elements to the hash table. ...
    (comp.lang.cobol)
  • Re: Why are tuples immutable?
    ... >>And how exactly do you propose to mutate an object without changing its ... >>If the hash values are the same, you lose because you didn't keep your ... keys being mutable objects, that they want to mutate those object while ... > objects used as keys in order to access it. ...
    (comp.lang.python)