http://www.perlmonks.org?node_id=995578


in reply to Epoch time conversion in CSV

For parsing and writing CSV, Text::CSV is your friend. And for datetime manipulations, you want DateTime.

use Text::CSV; use DateTime; use constant DATE_FORMAT => '%a %b %d %Y %T'; my $in_fh = \*DATA; my $out_fh = \*STDOUT; my $csv = Text::CSV->new({ allow_whitespace => 1 }); while (my $row = $csv->getline($in_fh)) { for my $col (0, 1) { my $dt = DateTime->from_epoch( epoch => $row->[$col], time_zone => '-05:00', ); $row->[$col] = $dt->strftime(DATE_FORMAT); } $csv->print($out_fh, $row); print {$out_fh} "\n"; } __DATA__ 1345752662, 1345752673, CLOSED, CRITICAL, Other fields etc
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'