in reply to Creating Hash of hash of hash dynamically

Thanks everyone, I know where I'm going now! -

I was groping towards davido's approach - starting with deepest hash first - but hit my learning ceiling (I hail from land of JavaScript) so thanks for the lesson, Dave.

Sorry I didn't give more background info:
the csv file (maybe 300 or so lines/records) is posted by the client, who gets to decide himself:
- how many levels of folder depth he wants on his website this month
- how many fields display for each record

So the first line of the parsed csv file gives me the FolderTitles list, annotated to tell the script how 'deep' the html site is going to be
The first few fields on each subsequent line tell me the path where that record will live, and the leftover fields make up the record itself.
Each line is always the same length.

I previously hacked up an undignified version of the site using arrays and it's been working fine (and fast) but hashes would be simpler

Anyway, thanks again,
rjc
  • Comment on Re: Creating Hash of hash of hash dynamically

Replies are listed 'Best First'.
Re^2: Creating Hash of hash of hash dynamically
by davido (Cardinal) on Oct 12, 2004 at 04:20 UTC

    I wish I could claim that I came up with the "build it in reverse" technique myself. I saw it first in a great book published by O'Reilly & Associates, "Mastering Algorithms with Perl". The book discusses (among many other topics) building linked lists, and one method is surprisingly similar to the solution I provided to your problem. Your situation was a little different, but being familiar with the Algorithms book provided me with the basic concept. I highly recommend the book.

    You can also learn a great deal about complex datastructures and Perl's references from the following POD's:

    • perlreftut - Tutorial on references.
    • perllol - Tutorial on building and manipulating lists of lists, and other similar datastructures using references.
    • perldsc - Perl Datastructure Cookbook... good stuff.
    • perlref - Of course, the definitive source.

    Happy hunting...


    Dave