I'm writing a script where I need to take rows of data and turn them into columns. A hash of arrays seemed like the obvious data structure to use, however I am having some problems getting the data back out.
Here is the problem snippet of code:
foreach $head (keys %hoa) {
my @data = @{$hoa{$head}};
$item = shift(@data);
print OUTFILE "$item";
print OUTFILE ",";
}
This dies with the error "Use of uninitialized value in string at..." and gives the line number of the line with the shift command. However, if I comment out the next line, the print of $item, the script seems to run just fine. If I print @data, that seems to work fine too. I've read the other nodes of for more info on hashes or arrays and I'm stumped.
One other thing I should mention: I've been writing Perl scripts that run on Unix and Mac OSX for a while. This is the first one I've tried writing to run on Windows. I've already run into a few minor yet irritating differences. I'm not sure if this is one of them or not, but if it matters I'm trying to run this under ActivePerl 5.8.8
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.