foreach (@probExpr) { print "$_\n"; #%distri{$_}=(); %distri{$_}=[]; }

Others have explained how to fix the syntax here, but even with that change, all this does is initialize each value of %distri to (a reference to) an empty anonymous array. Initializing variables to "empty" values is common practice in languages like C, but in Perl it is usually unnecessary and sometimes a sign of poor design. I will come back to this particular case in a moment...

&hashOfArraysRef(\$distri{$probExpr[0]});

This feels strange to me, and somewhat obfuscated, for code whose basic purpose is to assign something to that hash element. Yes, it is clear how it works when I look at the code for the subroutine, but apart from that additional context _this_ line could be... misleading. It would seem much more straightforward like this:

$disti{$probExpr[0]} = function_that_returns_anonymous_array();

Or, assuming your function really wants to assign different anonymous arrays to different elements, perhaps something more like this:

$disti{$probExpr[0]} = function_that_returns_anonymous_array($probEx +pr[0]);

Or even...

$disti{$_} = function_that_returns_anonymous_array($_) for @probExp +r;

Then the basic flow of what's going on would be fairly clear _without_ seeing the subroutine definition. Since one of the major purposes of subroutines is to factor out details so that the main flow of the code can be seen, that would seem a desirable outcome.

Further, the initialization loop above would then become superfluous, further simplifying the code.


Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.

In reply to Re: Function composing a hash of arrays. by jonadab
in thread Function composing a hash of arrays. by dislimit

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.