> any suggestions?
I'll try.
> @bags = param('handbag'); get all of the bags styles
Missing comment...
@bags = param('handbag'); # get all of the bags styles
> push %bags_ordered,$bag_name;
You can't push onto a hash, only an array. So either %bags_ordered need to
be an array, or you mean something else.
Maybe this is what you mean...
use strict; # a big bonus for debugging
use Data::Dumper; # for testing
my %bags_ordered;
my @bags = param('handbag'); # get all of the bags styles
my @bag_quantity = param('quantity'); # get all of the bags quantity
for (my $i = 0; $i < @bags; $i++) {
# split the bag item
my ($bag_name, $imgName) = split (/,/, $bags[$i]);
# create an empty hash if this is a new bag
$bags_ordered{$bag_name} = {} unless exists $bags_ordered{$bag_name};
# set the image name
$bags_ordered{$bag_name}->{image_name} = $imgName;
# set the quantity. should it be additive with +=?
$bags_ordered{$bag_name}->{quantity} = $bag_quantity[$i];
}
# print the structure for testing using Data::Dumper
print Dumper \%bags_ordered;
Rob
-----Original Message-----
From: David Gilden [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 04, 2003 4:57 PM
To: [EMAIL PROTECTED]
Subject: data structures
I am trying to build a data structure, and am tripping up here.
any suggestions?
Thx!
Dave
!/usr/bin/perl -w
.... snip...
@bags = param('handbag'); get all of the bags styles
@bag_quantity = param('quantity'); get all of the bags quantity
foreach my $bag (@bags){
($bag_name,$imgName) = split (/,/,$bag);
push %bags_ordered,$bag_name;
push %bags_ordered{$bag_name}{image_name} = $imgName;
}
foreach my $q (@bag_quantity){
push %bags_ordered{$bag_name}{$bag_quantity} =$q;
}
Data structure:
%bags_ordered = (
"bag-style1" => { price => 10,
image_name => 'FIO-142b-small',
quantity=> 5
},
"bag-style2" => { price => 12,
image_name => 'GUC-208-small',
quantity=> 5,
},
);
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]