sidsinha has asked for the wisdom of the Perl Monks concerning the following question:
I have an hash of keys and values as below. Each key has multiple values, but each value could reference a key. For a given input key, I need to print the values, and if the value is also a key, then print the value of that key in brackets as below:
Usb1 Usb2,Usb3 Usb2 val1,val2,Usb4 Usb3 val3 Usb4 val4
Input : Usb1 print Usb2[val1,val2,Usb4[val4]],Usb3[val3] Input : Usb2 print val1,val2,Usb4[val4]
The logic I tried is to first check if the input key exists in the hash then load the values of that key into an array Now, iterate through the array, print $_ , then compare if the value matches any key in the hash, if matches, print the value. But now, I dont get how long and how I can keep doing this, because the set of keys could reference another key and so on...
Any suggestions or examples could help. Thankyou
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Parsing through Hashes
by AppleFritter (Vicar) on Aug 29, 2014 at 09:45 UTC | |
by Anonymous Monk on Aug 29, 2014 at 23:31 UTC | |
by AppleFritter (Vicar) on Aug 30, 2014 at 09:32 UTC | |
Re: Parsing through Hashes
by sidsinha (Acolyte) on Aug 29, 2014 at 09:27 UTC |
Back to
Seekers of Perl Wisdom