raybies has asked for the wisdom of the Perl Monks concerning the following question:
Suppose I want an array of value pairs, suppose for the sake of arguments, vertices, like X,Y (though, they don't have to be numeric types, I'm thinking generic pairs). I want to keep the list of vertices in a list.
What's the best way to store/organize them in perl?
It seems so wasteful to use an array of hashes (key/value) for a single pair, with key names like X and Y.
%pair = ( X => 12, Y => 10); #then keep in a list like this... $pairlist[0] = \%pair;
And using the first (X) value as a key wouldn't work if you needed to repeat the value.
Of course, a simple array of arrays would work...%pair = (12 => 10); # no list required, but then (12,10) and then (12,5) wouldn't work...
@pair = (12,10); #with a list assigned like... $pairlist[0] = \@pair;
I guess I'm curious what y'all do?
I mean, besides making an object, which is a pain for something this simple, especially if I don't supplement my Perl with something like Moose, which I don't... (well maybe it's not a pain for you... but I'm pretty weak there...) ;)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Storing simple Value Pairs
by BrowserUk (Patriarch) on Oct 19, 2011 at 18:48 UTC | |
by raybies (Chaplain) on Oct 19, 2011 at 18:57 UTC | |
|
Re: Storing simple Value Pairs
by ikegami (Patriarch) on Oct 19, 2011 at 18:45 UTC | |
|
Re: Storing simple Value Pairs
by Marshall (Canon) on Oct 19, 2011 at 18:54 UTC | |
|
Re: Storing simple Value Pairs
by jeffa (Bishop) on Oct 19, 2011 at 18:43 UTC | |
by raybies (Chaplain) on Oct 19, 2011 at 18:46 UTC | |
|
Re: Storing simple Value Pairs
by pvaldes (Chaplain) on Oct 19, 2011 at 18:44 UTC | |
|
Re: Storing simple Value Pairs
by raybies (Chaplain) on Oct 19, 2011 at 19:02 UTC | |
by nabiana (Initiate) on Oct 19, 2011 at 20:07 UTC | |
by Marshall (Canon) on Oct 20, 2011 at 01:51 UTC |