Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

how to add values of one key to the other key value in a hash using perl.

by veerubiji (Sexton)
on Nov 02, 2011 at 16:04 UTC ( #935434=perlquestion: print w/ replies, xml ) Need Help??
veerubiji has asked for the wisdom of the Perl Monks concerning the following question:

hi monks, I have data like this in a variable. I used XML::Simple to get this data hash stucture

$var1={ 'studentaddres'=>{ 'address'=>[ { 'name'=>'mikky', 'number'=>'12', 'adress'=>' badvel,kadapa,a.p,india', }, { 'name'=>'vijju', 'number'=>'12', 'adress'=>' raipur,ananthapur,a.p,india +', }, { 'name'=>'shyam', 'number'=>'12', 'adress'=>' raighad,rajsthan,india', }, ], 'Subjects'=>[ { 'subjects'=>'7', 'names'=>'EDC,PDc,OS,CN,ITNM,CDS,ENG +LISH', } { 'subjects'=>'3', 'names'=>'EDC,CDS,ENGLISH', } { 'subjects'=>'2', 'names'=>'EDC,PDc', } { 'subjects'=>'5', 'names'=>'EDC,PDc,OS,CN,ITNM', } ], } 'university'=>{ 'name'=>'svu', 'location'=>'ravru', 'branch'=>{ 'electronics'=>{ 'student'=>[ { 'name'=>'mikky', 'number'=>'12', 'semester'=>{ 'Number'=>'1', 'subjects'=>'7', 'rank'=>'1' } }, { 'name'=>'vijju', 'number'=>'15', 'semester'=>[ { 'number'=>'1', 'subjects'=>'3', 'rank'=>'10' }, { 'number'=>'1', 'subjects'=>'2', 'rank'=>'1' } ] }, ] } } }; 'name'=>'sku', 'location'=>'ANTP', 'branch'=>{ 'electronics'=>{ 'student'=>[ { 'name'=>'shyam', 'number'=>'12', 'semester'=>{ 'Number'=>'3', 'subjects'=>'5', 'rank'=>'20' } }, ] } } };

In the above code I have three keys one is studentaddress,subjects and universitys. and I have arrays of values in each key. I have common values in each key like name and number in studentaddress is same in student name and number in the university values. by using similar value in the keys I need to add adress value from studentaddress key to the student tag in the university key. same like subjet names form subject key to the semister tag in the university key. I need help in the perl script to perform this operation. I am very new to perl

Comment on how to add values of one key to the other key value in a hash using perl.
Download Code

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://935434]
Approved by herveus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2016-05-02 07:01 GMT
Find Nodes?
    Voting Booth?