I had to do something similar in the recent past and here are two links that might be of help with the actual rotation/pivot portion of your solution:
using PDL->transpose on CSV file
In reply to Re: How to create pivot tables via perl?
by bfdi533
in thread How to create pivot tables via perl?
by rafa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |