Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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.

Replies are listed 'Best First'.
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.


      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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://352743]
[Cosmic37]: thank you for advice
[Cosmic37]: peach greets jedi
[Cosmic37]: ok this one works better fullpage chat
[Cosmic37]: test
[Cosmic37]: sort of anyway... hurls some peaches... :-D

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2017-06-29 16:27 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.