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

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..

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..