Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Re: hash, a troublemaker?

by flyingmoose (Priest)
on May 12, 2004 at 14:11 UTC ( #352743=note: print w/ replies, xml ) Need Help??


in reply to Re: hash, a troublemaker?
in thread hash, a troublemaker?

This is rather ugly, you have a set of lookups for various values without correlation to structures, while the opening example does have problems of hash abuse with misspelling, I'd MUCH rather see field identifiers as constants and an HoH as a datastructure rather than having unaffiliated fields.

i.e. $records{$person}{$K_AGE}

That way you keep records grouped. Since Perl doesn't have real structures of any merit, the next logical step is to go to an OO representation and use functions/etc (maybe one of those MethodMaker deals) to prevent accidental typos.

At minimum, the Hash::Util method provides locking while preserving the logical representation of the data (edit: and clean Data::Dumper dumpability!).

Keeping fields seperated without context, IMHO, is the worst thing you can do.


Comment on Re: Re: hash, a troublemaker?
Download Code
Re: hash, a troublemaker?
by Abigail-II (Bishop) on May 12, 2004 at 14:17 UTC
    This is just the same technique I use for InsideOut objects, so going to an OO model wouldn't be much of a change for me. ;-). And if you use functions, you can still make typos in the functions when you access the attributes - which is why I developed InsideOut objects in the first place.

    Abigail

      yep, that's a lot cleaner when the collections of fields start having namespace...
Re: Re: Re: hash, a troublemaker?
by Doraemon (Beadle) on May 12, 2004 at 14:35 UTC
    Sorry Abigail-II :)
    I agree with flyingmoose. Related fields should be grouped together, with a name represent these related data. At this point i strongly support the reference mechanism, but somehow, we need to create a reference that have information about the data that it's pointing to.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://352743]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2014-08-29 18:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (286 votes), past polls