in reply to Function composing a hash of arrays.
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.
|
|---|