Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

time local module

by varalaxmibbnl (Acolyte)
on Dec 14, 2013 at 13:19 UTC ( #1067137=perlquestion: print w/ replies, xml ) Need Help??
varalaxmibbnl has asked for the wisdom of the Perl Monks concerning the following question:

hi monks when i run the following script

#!/usr/bin/perl $now = time(); use Time::Local; open(LEASE, "/var/lib/dhcp3/dhcpd.leases"); foreach $line (<LEASE>) { chomp($line); $data = 1 if $line =~ /^lease /; $data = 0 if $line =~ /^}/; if ($data) { if ($line =~ /^lease/) { $ip = (split(" ", $line))[1]; } elsif ($line =~ /^ starts/) { ($date, $time) = (split(" ", $line))[2,3]; ($y, $m, $d) = split("/", $date); ($H, $M, $S) = split(":", $time); $start = timelocal($S,$M,$H,$d,$m,$y); } elsif ($line =~ /^ ends/) { ($date, $time) = (split(" ", $line))[2,3]; ($y, $m, $d) = split("/", $date); ($H, $M, $S) = split(":", $time); $stop = timelocal($S,$M,$H,$d,$m,$y); } elsif ($line =~ /^ hardware ethernet/) { $mac = (split(" ", $line))[2]; $mac =~ s/;//; } elsif ($line =~ /^ client-hostname/) { $client = (split(/\"/, $line))[1]; } } else { print localtime($start) . "\t" . localtime($stop) +. "\t$ip\t$mac\t$client\n" if $stop >= $now; $ip = ""; $start = ""; $stop = ""; $mac = ""; $cli +ent = ""; } } close(LEASE);
it gives "Month '12' out of range 0..11 at dhcp.pl line 20" error...i don't understand what that error means properly please help me out to solve the problem...thanks in advance..

Comment on time local module
Download Code
Re: time local module
by ww (Bishop) on Dec 14, 2013 at 13:42 UTC
    See perldoc Time::Local:
    It is worth drawing particular attention to the expected ranges for the values provided. The value for the day of the month is the actual day (ie 1..31), while the month is the number of months since January (0..11). This is consistent with the values returned from "localtime()" and "gmtime()".

    Generally, the documentation that came with your copy of Perl will provide guidance (or, imagine!) even answers on questions such as this.

    If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.
      tanks for reply..

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1067137]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-12-26 21:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls