Think about Loose Coupling | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
G'day pldanutz, I generally think it's better to pass around scalars than entire data structures, so returning a reference to that hash would be my preference. If you wrapped $h{$k} in @{...}, you could dispense with if (! $h {$k}) { $h {$k} = [] } entirely. Even if you're using 5.012 for other reasons elsewhere in your code, I see little, if any, value in using each here. It's easy to write it for any Perl5. Putting all that together, you could code occurrences() like this instead:
If you were looking for a golf answer, you could start with the following and then proceed to remove whitespace until illegibility was achieved. :-)
Here's my tests: <Reveal this spoiler or all in this thread>
-- Ken In reply to Re: array => hash of occurrence indexes
by kcott
|
|