If I have a multiline array and it contains for example the following integers with different numbers of integers per line:
1 1 1 2 1 1
2 1 4 1
2 1 1 3 1 6
How do I convert it to an array of counts in perl with zeros for keys with no counts? I can do it for the single array case using map, but I’m struggling with this multiline case/array of array case.
#For line 1, 1 => 5, 2 => 1
#For line 2, 1 => 2, 2 => 1, 4 => 1
#For line 3, 1 => 3, 2 => 1, 3 => 1, 6 => 1
So the result looks like this:
5 1 0 0 0 0
2 1 0 1 0 0
3 1 1 0 0 1
Thanks!
This seems to do what is required. It does the obvious thing of building an array of hashes of counts, then finds the maximum value amongst the keys of the hashes for building a display
output