I wonder how you tell the folders and fields apart, why you would want a CSV file with a variable number of values per line, and what you are going to do with the %BIGLIST when you've created it. I think your datastructure might be overly complex.

But lets say that you REALLY want a tree structure for this kind of thing:

sub add_line { my ($tree,@line) = @_; my $first_element = shift @line; if (is_a_folder_title($first_element)) { # TODO: implement is_a_fol +der_title() $tree->{$first_element} ||= {}; # create empty hashref if none ex +ists, yet add_line($tree->{$first_element},@line); } else { $tree = [ $first_element, @line ]; } }

To get the values out again:

sub get_elements { my ($tree,@folder_names) = @_; return $tree unless @folder_names; my $subtree = $tree->{shift(@folder_names)}; return get_elements($subtree,@folder_names); }
If you have a seperate list of fields and folders, it's a lot easier to use a "simple" hash of arrays instead:
$directories{ join("/",@folder_names } = \@fields; my @fields = @{ $directory{ join("/",@folder_names) } };

In reply to Re: Creating Hash of hash of hash dynamically by Joost
in thread Creating Hash of hash of hash dynamically by rjc

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.