Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Epoch time conversion in CSV

by tobyink (Abbot)
on Sep 25, 2012 at 15:44 UTC ( #995578=note: print w/replies, xml ) Need Help??


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'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://995578]
help
Chatterbox?
[Cosmic37]: I'm wondering whether there is a specific/(or at least "usual") command or does one take a copy before undefining and then copy it back after slurping file into a string?
[BarApp]: I need help accessing perl files. I need permission!!!
[Cosmic37]: I wish thee a peachy life and express gratitude for considering my pathetic questions
[erix]: record separator
[Cosmic37]: Permissions are interesting earthlings. Did nature determine who gives permission and who asks permission. Who was the first to get permission? Are you not related to them as one big earthling family?

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (9)
As of 2017-06-29 16:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (672 votes). Check out past polls.