in reply to hash, a troublemaker?
Why are you using a hash in this case? It looks like you are using it where one would use a struct in C. Now, either of two things could be the case: you just have a single hash with this role, or it's one of many. In the first case, you can avoid the hash altogether, and just use variables, $name, $age, etc. If you have more of them, just turn them inside-out. Say you would normally have %person1, %person2, %person3, etc, each with an age, a name, and perhaps more,
something like:
Instead of hashes for the entities, and attributes as the keys, make hashes for the attributes, using the entities as attributes - just make sure the entities are unique.my (%person1, %person2, %person3, ...); $person1 {name} = "..."; $person1 {age} = ...; $person2 {name} = "..."; $person2 {aeg} = ...; # Oopsie. $person3 {name} = "..."; $person3 {age} = ...;
my (%age, %name); my $entitie_count = 0; my $person1 = ++ $entitie_count; my $person2 = ++ $entitie_count; my $person3 = ++ $entitie_count; $name {$person1} = "..."; $age {$person1} = ...; $name {$person2} = "..."; $aeg {$person2} = ...; # Compile time error with use strict. $name {$person3} = "..."; $age {$person3} = ...;
Abigail
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: hash, a troublemaker?
by flyingmoose (Priest) on May 12, 2004 at 14:11 UTC | |
by Abigail-II (Bishop) on May 12, 2004 at 14:17 UTC | |
by flyingmoose (Priest) on May 12, 2004 at 14:26 UTC | |
by Doraemon (Beadle) on May 12, 2004 at 14:35 UTC |
In Section
Seekers of Perl Wisdom