I wrote a perl script using Tie::Handle::CSV to process a bunch of data in a csv file and print out only what I need into a new csv file. Right now, I print out the header line with all of the field names by just a hardcoding it in like so:
print '"TERM", "STUDENT ID", "NAME", ..."'."\n";
I suspect this is a dumb way of doing this, but I don’t know how to get access to the header from within the Tie::Handle::CSV object. It’s instantiated like so,
my $fh = Tie::Handle::CSV->new($file,header=> 1);
and data is accessed like so,
$line -> {'CATALOG_NBR'}
I know enough to know this is a hash-reference, but not enough to know how to print the header using this rather than hardcoding it. Obviously, “they” usually change the precise column names and ordering just after I get the script working again each term.
Thanks a lot for any help!
JA
If header is defined and not an array reference, then the first line of the document will be used as header. Sadly, there is no method to get such header as originally was, so short of reading the first line using the header option as false, storing it (it is already an array ref) and closing the file and rereading again, I don’t see an easier way to do it.