Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

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 line 20" error...i don't understand what that error means properly please help me out to solve the problem...thanks in advance..

Replies are listed 'Best First'.
Re: time local module
by ww (Archbishop) 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1067137]
Approved by toolic
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2017-04-29 16:30 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (533 votes). Check out past polls.