in reply to Re^2: Bulk Hash Assignment
in thread Bulk Hash Assignment

well, this looks simple. i haven't run it, but it looks like it will work if %$p and %$q implement exactly the same keys. my example works on the intersection of keys between %foo and %bar (only the keys both hashes share.) perhaps i solved a more general problem than the original poster requested.

question: what happens to your code if a key exists in %p2q, but not in %$p? my code will not auto-vivify a key in %$q. will yours?

by the way, values and keys are guaranteed to output in the same order (in the same hash.) this is by no means guaranteed in different hashes. see each for a little detail.

~Particle ;Þ

Replies are listed 'Best First'.
Re^4: Bulk Hash Assignment
by tadman (Prior) on Apr 17, 2002 at 22:20 UTC
    Well, the idea was that you would only ask to export that particular key if it was defined in p in the first place. Further to that, since you are exporting from p to q, if something is not in q, then it should be created. After all, the idea is to move data from p to q. If q was an empty hash, clearly nothing would ever be inserted into it.

    Also, as best as I can tell, reading from a hash at the root level does not create keys, even when using hash slices.

    The idea for schlep() is to move data simply and efficiently from one or more hashes into a single hash, remapping as required since the two namespaces likely differ to some degree.