cucugirl
asked on
making a different data structure
one more question.. I want to make an HoH from an array but don't know why when I use print Dumper it does not look like a HoH it looks more like HoA i would say... attached is what I got...
i want something like this:
my %data = {'15'=>{'MATH'=>'412'},'16 '=>{'Therm o'=> '235'},'17'=>{'statics'=>' 211'}, '18'=>{'design'=>'250'}}; I currently have this:
my %data = {'15'=>['MATH'=>'412'],'16 '=>['Therm o'=> '235'],'17'=>['statics'=>' 211'], '18'=>['design'=>'250']};
i want something like this:
my %data = {'15'=>{'MATH'=>'412'},'16
my %data = {'15'=>['MATH'=>'412'],'16
my $counter = $#newper+1;
foreach my $check (sort @table){
push(@{$data{$counter}},%$check);
$counter++;
}
my @table = ({'MATH'=>'412'},{'Thermo'=> '235'},{'statics'=>'211'}, {'design'=>'250'});
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
['MATH'=>'412']
is the same as
['MATH','412']
=> is like , except that it automatically treats the left side as a bareword so you don;t get a warning fot
[math=>'412']
is the same as
['MATH','412']
=> is like , except that it automatically treats the left side as a bareword so you don;t get a warning fot
[math=>'412']
since @table contains references, sort @table will sort by the stringified references, which would come out in order of its address in memory, which is not very meaningful, ad probably not what you wanted.
@{$data{$counter}} will autovivify $data{$counter} as an array
did you mean
$data{$counter}={%$check}
instead of
push(@{$data{$counter}},%$ check)
did you mean
$data{$counter}={%$check}
instead of
push(@{$data{$counter}},%$
What is the purpose of having a hash with sequential numeric keys instead of an array?
ASKER
my %data = {'15'=>['MATH','412'],'16'