Solved

making a different data structure

Posted on 2009-05-07
6
138 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
stftime format 4 55
Writing a parser for java language 4 78
Regular Expression for URL 10 96
How to generate square thumbnail using perl 13 79
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…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

816 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

10 Experts available now in Live!

Get 1:1 Help Now