arunhorne has asked for the wisdom of the Perl Monks concerning the following question:
Hi all,
I have a hash in the following format (the notation is my own brand ;) but what it shows is a scalar on the left mapping to an array of values (the right hand side is of course a ref to the actual array):
1 -> @{a, b, c} 2 -> @{d, e, f} 3 -> @{g, h, i}
My first task i needed to do to this hash was print out each key, with each corresponding value on a new line, thus:
1, a 1, b ... 3, h 3, i
This was straightforward. My new requirement is to print in the form:
a, 1 b, 1 c, 1 ... g, 3 h, 3 i, 3
As an extra caveat I also want to make sure the output is ordered by the output, i.e. as it is in the above, a before b etc.
Has anyone got any nice perl ways of doing this or am I going to have to go for brute force set of nested foreach statements? I certainly have no idea as to making the output ordered!
By the way I still need to maintain the hash in its original form as the first output method (the one I have working) is still required.
Thanks, Arun
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reorganising a Hash for Output
by graff (Chancellor) on May 07, 2002 at 13:22 UTC | |
by arunhorne (Pilgrim) on May 07, 2002 at 13:43 UTC | |
|
Re: Reorganising a Hash for Output
by talexb (Chancellor) on May 07, 2002 at 13:13 UTC | |
|
Re: Reorganising a Hash for Output
by bmcatt (Friar) on May 07, 2002 at 13:30 UTC | |
by tachyon (Chancellor) on May 07, 2002 at 15:13 UTC | |
|
Re: Reorganising a Hash for Output
by demerphq (Chancellor) on May 07, 2002 at 15:32 UTC |