There's always MTOWTDI ... You've just managed to find one of the more extreme methods (without going into function calls). As cog said, you can just assign $tokens{$id} = $href. But the other way (my preference) would be:

while (<$fd>) { my %href = map { split '=', $_, 2 } split ';'; my $id = (split '\.', $href{TOKEN})[1]; $tokens{$id} = \%href; }
Of course, there are a bazillion ways to get the text between the first and second dot, but that's not the question here, so I'm leaving well enough alone. The only real change to that line was the removal of the arrow notation since I changed from using a hashref to using just a plain hash. Each time through the loop, we'll get a new hash, and the %tokens hash will have references to no-longer-named hashes that have otherwise fallen out of scope. Either solution (cog's or this one) should be faster than yours (no copying), but otherwise there's probably no significant difference between them (likely the same speed). The only difference is the sigils.


In reply to Re: Better way to add refs to an array or hash? by Tanktalus
in thread Better way to add refs to an array or hash? by Argel

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.