D
Damian James
Hi folks,
So I wanted to define a lookup table that I would later need to
iterate over in a specific order. That's easy enough, there are
many ways to do it; but I specifically wanted to keep the neat,
visually oriented table in my code:
my @mappings = (
field1 => 'otherLongwindedDirectoryAttribute',
field2 => 'kitchenSink',
field3 => 'userDistanceBetweenEyes'
);
my %lookup = @mappings;
my @fields = @mappings[ map $_*2, 0..($#mappings/2) ];
....where obviously I am only interested in %lookup and @fields, but
want to keep the table in the interests of easy alteration.
So how might I avoid defining @mappings? Is there a simpler, shorter
or more elegant 'hashificator' that might be suitable in place of the
arithmetic one I've shown? People maintaining this later may well not
be able to find their own um, keyboard, with detailed directions and
a map, but just might be able to change a lookup table if it's clear
enough and the instructions are sufficiently detailed.
I know I can:
my %lookup;
@lookup{ my @fields = qw/field1 field2 field3/ } =
qw/other kitch user/;
But that sacrifices the vertical orientation, and that just won't fit
neatly with the rather long directory attribute names.
This is obviously a style question more than anything, so the more
playful the suggestions the better I guess
.
--damian
So I wanted to define a lookup table that I would later need to
iterate over in a specific order. That's easy enough, there are
many ways to do it; but I specifically wanted to keep the neat,
visually oriented table in my code:
my @mappings = (
field1 => 'otherLongwindedDirectoryAttribute',
field2 => 'kitchenSink',
field3 => 'userDistanceBetweenEyes'
);
my %lookup = @mappings;
my @fields = @mappings[ map $_*2, 0..($#mappings/2) ];
....where obviously I am only interested in %lookup and @fields, but
want to keep the table in the interests of easy alteration.
So how might I avoid defining @mappings? Is there a simpler, shorter
or more elegant 'hashificator' that might be suitable in place of the
arithmetic one I've shown? People maintaining this later may well not
be able to find their own um, keyboard, with detailed directions and
a map, but just might be able to change a lookup table if it's clear
enough and the instructions are sufficiently detailed.
I know I can:
my %lookup;
@lookup{ my @fields = qw/field1 field2 field3/ } =
qw/other kitch user/;
But that sacrifices the vertical orientation, and that just won't fit
neatly with the rather long directory attribute names.
This is obviously a style question more than anything, so the more
playful the suggestions the better I guess
--damian