Let me guess... LPC? :-) There have been a few questions in that direction lately. I had not heard of it before.

Perhaps you should use an anonymous array for a "key", instead of a list. You then no longer need to wrap each pair in an anonymous array. The resulting code would look more Perlish, IMO.

my %hash = expand_keys( ['key1', 'key2', 'key3'] => 'Value for key1, key2, and key3', [qw( key4 key5 key6) ] => 'Value for key4, key5, key6', 'simple key' => 'Value for simple key' );
Now it's just a matter of defining expand_keys():
sub expand_keys { my @result; while(@_) { my $key = shift; my $value = shift; if(ref $key) { push @result, $_, $value foreach @$key; } else { push @result, $key, $value; } } return @result; }
You could populate a hash instead of pushing the data onto an array, in the sub, I suppose. I think it might be a tiny bit slower, because you would then be building two hashes, instead of just one (and an array).

In reply to Re: Splitting an array to populate hash by bart
in thread Splitting an array to populate hash by Coruscate

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.