You could treat it as string, transform to final version and do eval:

#!perl -l @strings = <DATA>; for(@strings) { chomp; s/,/'}{'/g; s/^/\$hash{'/; s/$/'}++/; print "eval $_"; eval $_; } use Data::Dumper; print Dumper \%hash; __DATA__ string1,string2,string3,string4 string3,string4 string1,string2,string3
Output:
c:\>test.pl eval $hash{'string1'}{'string2'}{'string3'}{'string4'}++ eval $hash{'string3'}{'string4'}++ eval $hash{'string1'}{'string2'}{'string3'}++ $VAR1 = { 'string3' => { 'string4' => 1 }, 'string1' => { 'string2' => { 'string3' => 5393161 } } };
But as you can see there is a problem to solve: 'string3' => 5393161 which was created as reference to hash, but then replaced by value. What do you want to do in such situation?

In reply to Re: variable number of hash of hashes by grizzley
in thread variable number of hash of hashes by Boetsie

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.