No such thing as a small change | |
PerlMonks |
Searching and printing complex data structuresby Anonymous Monk |
on Apr 10, 2013 at 17:59 UTC ( [id://1028018]=perlquestion: print w/replies, xml ) | Need Help?? |
Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question: Dear Monks, I have a quite complicated object (for various reason it has to be like this) and by using this example I want to ask how to do to specific tasks. I hope it will be easy to understand. #Created by using; push @{ $Second{Company}->{Identifier} }, Element;
1) I want to know how many 'b' elements is there in Company_A. Usually I would use something like map { $Count+= 1 if 'a' eq values %Hash{Company_A}{$_} } values %Hash{Company_A}; but it will only access the first element of each Identifier. How can I write a map command to go through every element? 2) When I need to print this hash I have to look if each identifier has one or more elements (scalar) and fork the prints to print out everything in line by line case (foreach and use count++). Amount of elements vary and there is a lot of data inside so I don't want to create duplicate entries</pp>
Some Identifiers have more elements (always equal amount) and other have only one. I need to print the ones with multiple elements separately - they share the elements which only appear once. Because I am doing it for separate objects I was wondering if there is a way to print everything in one block with a single command? Thanks so much for any tips. Humble apprentice
Back to
Seekers of Perl Wisdom
|
|