Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: localtime function

by Anonymous Monk
on Jan 27, 2015 at 09:43 UTC ( [id://1114615]=note: print w/replies, xml ) Need Help??


in reply to localtime function

By the way, what is "TEXT::CSV"? I only know of Text::CSV - does your code compile and run as you've shown it?

You may also want to have a look at the Basic debugging checklist.

Replies are listed 'Best First'.
Re^2: localtime function
by rsodhia (Novice) on Jan 27, 2015 at 10:11 UTC

    I am reading from a csv file name: dDos_flows.csv, which has whole lot of entries which I am storing them all in a array & filtering out data2. which is: startTime 1421744559358 1421744614728 1421744621032 1421724767767 Now this particular column has the time in the unix timestamp format, which I intent to convert it into standard time format & place it back into the dDos_flows.csv file.

    The output I am getting: Wed Dec 31 16:00:00 1969 Thu Apr 17 13:15:58 47023 Fri Apr 18 04:38:48 47023 Fri Apr 18 06:23:52 47023 Sat Aug 31 11:36:07 47022 Thu Jan 30 16:28:48 47023 Wed Apr 16 09:25:01 47023 This is not the correct time. Besides I am getting some warning as well Use of uninitialized value $data2 in localtime at D:\ddos.pl line 20, <$fh> li ne 1. Wed Dec 31 16:00:00 1969 Use of uninitialized value $data2 in localtime at D:\ddos.pl line 20, <$fh> li ne 2. Wed Dec 31 16:00:00 1969 Argument "\x{73}\x{74}..." isn't numeric in localtime at D:\ddos.pl line 20, <$f h> line 3. Use of uninitialized value $data2 in localtime at D:\ddos.pl line 20, <$fh> li ne 22. Wed Dec 31 16:00:00 1969 Use of uninitialized value $data2 in localtime at D:\ddos.pl line 20, <$fh> li ne 23. Wed Dec 31 16:00:00 1969 Use of uninitialized value $data2 in localtime at D:\ddos.pl line 20, <$fh> li ne 24. Wed Dec 31 16:00:00 1969

      These numbers are way bigger than the current timestamp what is 1422354181. The code below would solve the problem if the timestamps were valid.

      my $res = 'startTime 1421744559358 1421744614728 1421744621032 1421724 +767767'; my @res = split(' ', $res); shift @res; foreach my $t (@res) { print localtime($t) . "\n"; }
        As per pme, I made the following changes but nothing worked.
        #!/usr/bin/perl use strict; use warnings; use XML::CSV; use Text::CSV; use Time::Local; my @d; my %ha; my $file = 'dDos_flows.csv'; my $file1 = 'dDos_flows1.csv'; open(my $fh,'<:encoding(UTF-8)',$file); open(my $fh1,'>:encoding(UTF-8)',$file1); while(my $f=<$fh>) { chomp $f; my @data=split ",",$f; my $res=$data[2]; #print "$res \n"; my @res= split(' ', $res); shift @res; foreach my $t (@res) { print localtime($t) . "\n"; } #my $conv=scalar(localtime($data[2])); #print "$conv \n"; }
        output
        Use of uninitialized value $res in split at D:\ddos.pl line 21, <$fh> +line 1. Use of uninitialized value $res in split at D:\ddos.pl line 21, <$fh> +line 2. Use of uninitialized value $res in split at D:\ddos.pl line 21, <$fh> +line 22. Use of uninitialized value $res in split at D:\ddos.pl line 21, <$fh> +line 23. Use of uninitialized value $res in split at D:\ddos.pl line 21, <$fh> +line 24.

      Please use <code> tags to preserve formatting.

      localtime accepts a time value in seconds. I am guessing that your time values are in milliseconds, so you need to divide them by 1000 to get seconds. If that loss of precision is not acceptable, you may want to switch to a module to handle your time processing needs, such as DateTime.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1114615]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (4)
As of 2024-04-24 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found