Thanks Dan and the rest of the list for helping hone my PERL skills.
Below is the data structure I am using, I think it is a HoH -- Hash of Hash
Did get that right ? :)
> Well 'better and correct' depends on what your design says, we cannot
> tell that. They are doing different things, that I can tell you for
> sure. So the question becomes, do you want to assign an empty anonymous
> hash (hash ref) in the case that the key doesn't exist, or do you want
> to assign the same value to the key in that case?
# This is the data structure
%bags_ordered = (
"bag-style-fur" => { price => 10,
image_name => 'FIO-142b-small',
quantity=> 2
},
"bag-style-leather" => { price => 12,
image_name => 'GUC-208-small',
quantity=> 5,
},
);
....
What I was looking for was way to initialize the %bags_ordered
and remove the 'unless exists'. Does this test do something
that I am not seeing or understanding like prevent two 'keys'
with different values?
%bags_ordered =(); # ok
%bags_ordered = {}; # not ok -- Reference found where even-sized list expected
......
@bags = param('handbag'); #CGI.pm
##
foreach my $bag (@bags){
$bags_ordered{$bag} = {} unless exists $bags_ordered{$bag};
}
##
# Is the code below -- better or correct?
foreach my $bag (@bags){
$bags_ordered{$bag} = $bag unless exists $bags_ordered{$bag}
}
Thanks for your time
Dave
( kora musician / audiophile / web master @ cora connection / Ft. Worth, TX, USA)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]