I think something like this is what you want,

use Data::Dumper; my %kid; while (<DATA>) { chomp; my @line = split /,/; $kid{$line[1]}{$line[2]}{$line[3]} = { duration => $line[4], function_name => $line[5] }; } print Dumper(\%kid); __DATA__ 1,2,3,4,100,A 10,20,30,40,200,B 11,21,31,41,300,C 12,22,32,42,400,D 13,23,33,43,500,E 13,23,33,53,600,F 13,23,33,63,700,G 13,23,34,73,800,H 13,23,34,83,900,I 13,24,35,93,1000,J 13,24,36,103,1100,K
That prints the data structure as:
$VAR1 = {
          '22' => {
                    '32' => {
                              '42' => {
                                        'function_name' => 'D',
                                        'duration' => '400'
                                      }
                            }
                  },
          '21' => {
                    '31' => {
                              '41' => {
                                        'function_name' => 'C',
                                        'duration' => '300'
                                      }
                            }
                  },
          '24' => {
                    '35' => {
                              '93' => {
                                        'function_name' => 'J',
                                        'duration' => '1000'
                                      }
                            },
                    '36' => {
                              '103' => {
                                         'function_name' => 'K',
                                         'duration' => '1100'
                                       }
                            }
                  },
          '23' => {
                    '33' => {
                              '63' => {
                                        'function_name' => 'G',
                                        'duration' => '700'
                                      },
                              '53' => {
                                        'function_name' => 'F',
                                        'duration' => '600'
                                      },
                              '43' => {
                                        'function_name' => 'E',
                                        'duration' => '500'
                                      }
                            },
                    '34' => {
                              '83' => {
                                        'function_name' => 'I',
                                        'duration' => '900'
                                      },
                              '73' => {
                                        'function_name' => 'H',
                                        'duration' => '800'
                                      }
                            }
                  },
          '2' => {
                   '3' => {
                            '4' => {
                                     'function_name' => 'A',
                                     'duration' => '100'
                                   }
                          }
                 },
          '20' => {
                    '30' => {
                              '40' => {
                                        'function_name' => 'B',
                                        'duration' => '200'
                                      }
                            }
                  }
        };
Is that what you were after?

Deep hashes like this are not the easiest thing to work with. Care must be taken to check existence of a key at each level while looking things up. From the feel of this sample problem, it's possible that Graph will make a more comfortable representation of the data.

After Compline,
Zaxo


In reply to Re: Hashes by Zaxo
in thread Hashes by flemi_p

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.