perl - Can you use array elements when adding a new line to a CSV file? -
i writing perl script , using class::csv module. have array of numbers, 5 elements long
$values[0] - $values[4] i trying add new line csv file , populate new line values array. keep receiving error when try run script:
failed create csv line line: 10252205 @ /usr/lib/perl5/site_perl/5.8.8/class/csv.pm line 257 class::csv::line::string('class::csv::line=hash(0x1f2d0f20)') called @ /usr/lib/perl5/site_perl/5.8.8/class/csv.pm line 435 class::csv::string('class::csv=hash(0x1f2c1c00)') called @ catchmailstats.pl line 116 here code csv construction:
# create csv file current data $csv = class::csv->new( fields => [qw/month notspam probable quarantine spam total/], ); # creates first row (headers) $csv->add_line({ month => 'month', notspam => 'notspam', probable => 'probable', quarantine => 'quarantine', spam => 'spam', total => 'total' }); # creates second row (values) $csv->add_line([$values[0], $values[1],$values[2],$values[3],$values[4], $total]); i have tried using other notation style:
# creates second row (values) $csv->add_line({ month => $values[0], notspam => $values[1], probable => $values[2], quarantine => $values[3], spam => $values[4], total => $total }); neither style has worked. here have noticed, though. final variable, $total, sum of $values[1] through $values[4]. variable work fine.
so real question is: why won't references elements in array work, summation of elements same array, compile without problem? , how can add_line function accept array elements?
i think in values list, there's hash ref needs dereferenced.
use data::dumper in code :
use data::dumper; print dumper @values; and post output, see.
Comments
Post a Comment