On Nov 24, 2005, at 12:11, Alexandre Checinski wrote:

Hello everobody,
I'm new to this list.

I have a problem to solve that have been mesing with for quite a few days now.

I have lists that looks like this :
(A,B,C,1,5)
(A,B,C,1,2)
(A,B,2,1,2)
(A,B,C,D,1)
(A,B,Y)

And I would like to get something like this :
{
   A => {
           B => {
                   C => {
                          1 => {
                                  5 => 1,
                                  2 => 1
                                  }
                          },
                          D => {
                                 1 => 1
                                 }
                   2 =>{
                          1 => {
                                 2 => 1
                                 }
                         }
                   },
           Y => 1
           }
}

Has anyone any idea on how to do it?

Just in case, looking at the last 1s I wonder whether you need that structure, or would it be more concise to have a hash where the keys can be arrays. The usage of such a hash would be

    $h{['A', 'B', 'C', 1, 2]} = 1;

If that was the case there are some modules on CPAN that provide them, like Tie::ListKeyedHash or Hash::MultiKey.

-- fxn

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to