Solved

making a different data structure

Posted on 2009-05-07
6
137 Views
Last Modified: 2012-05-06
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'=>{'Thermo'=> '235'},'17'=>{'statics'=>'211'}, '18'=>{'design'=>'250'}}; I currently have this:
my %data  =  {'15'=>['MATH'=>'412'],'16'=>['Thermo'=> '235'],'17'=>['statics'=>'211'], '18'=>['design'=>'250']};


my $counter = $#newper+1;

   

   foreach my $check (sort @table){

      

      push(@{$data{$counter}},%$check);

   

   $counter++;

   

   }
 

my @table = ({'MATH'=>'412'},{'Thermo'=> '235'},{'statics'=>'211'}, {'design'=>'250'});

Open in new window

0
Comment
Question by:cucugirl
  • 5
6 Comments
 

Author Comment

by:cucugirl
ID: 24327973
my bad... i currently have this:

my %data  =  {'15'=>['MATH','412'],'16'=>['Thermo', '235'],'17'=>['statics','211'], '18'=>['design','250']};
0
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 24328008
my %data = (map{$couner++=>$_}@table);
0
 
LVL 84

Expert Comment

by:ozo
ID: 24328048
['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']
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 84

Expert Comment

by:ozo
ID: 24328156
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.
0
 
LVL 84

Expert Comment

by:ozo
ID: 24328190
@{$data{$counter}} will autovivify $data{$counter} as an array
did you mean
$data{$counter}={%$check}
instead of
push(@{$data{$counter}},%$check)
0
 
LVL 84

Expert Comment

by:ozo
ID: 24328222
What is the purpose of having a hash with sequential numeric keys instead of an array?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now