time stamp perl script error out of range 1..31

Hi,

while running the perl script i am getting this error message ,
Day '' out of range 1..31 at rsty.sh line 44

what do iam missing in the script, any suggestion
#!/usr/bin/perl
use Time::Local;
my $wday = $ARGV[0];
my $month = $ARGV[1];
# convert the month shortname into 0-11 number
if ( $month eq "Jan" ) { $mon = 0 }
elsif ( $month eq "Feb" ) { $mon = 1 }
elsif ( $month eq "Mar" ) { $mon = 2 }
elsif ( $month eq "Apr" ) { $mon = 3 }
elsif ( $month eq "May" ) { $mon = 4 }
elsif ( $month eq "Jun" ) { $mon = 5 }
elsif ( $month eq "Jul" ) { $mon = 6 }
elsif ( $month eq "Aug" ) { $mon = 7 }
elsif ( $month eq "Sep" ) { $mon = 8 }
elsif ( $month eq "Oct" ) { $mon = 9 }
elsif ( $month eq "Nov" ) { $mon = 10 }
elsif ( $month eq "Dec" ) { $mon = 11 };
my $mday = $ARGV[2];
# initialize time varialble and split hours (24 hr format), minutes, seconds into an array
my $time = $ARGV[3];
@time = split /:/, $time;
# if the timezone is left out of the input, the position of year becomes 5th in ARGV
my $year = $ARGV[4];

$epoch= timelocal($time[2], $time[1], $time[0], $mday, $mon, $year);
print "$epoch\n";

Thanks
saha

What is typical input (parms ) for your script?

we are calling this script into another file where the parameter is
Sun Jul 31 11:58:54 2009

Most likely the arguments you pass the script aren't set/passed correctly because July (correctly set to 6 for Time::Local) does have 31 days. The code you posted works for me as-is.

Not sure how, but it seems like you are passing 2 or less parameters (instead of 5) to this Perl script:

$ 
$ cat testscr.pl
#!/usr/bin/perl
use Time::Local;
my $wday = $ARGV[0];
my $month = $ARGV[1];
# convert the month shortname into 0-11 number
if ( $month eq "Jan" ) { $mon = 0 }
elsif ( $month eq "Feb" ) { $mon = 1 }
elsif ( $month eq "Mar" ) { $mon = 2 }
elsif ( $month eq "Apr" ) { $mon = 3 }
elsif ( $month eq "May" ) { $mon = 4 }
elsif ( $month eq "Jun" ) { $mon = 5 }
elsif ( $month eq "Jul" ) { $mon = 6 }
elsif ( $month eq "Aug" ) { $mon = 7 }
elsif ( $month eq "Sep" ) { $mon = 8 }
elsif ( $month eq "Oct" ) { $mon = 9 }
elsif ( $month eq "Nov" ) { $mon = 10 }
elsif ( $month eq "Dec" ) { $mon = 11 };
my $mday = $ARGV[2];
# initialize time varialble and split hours (24 hr format), minutes, seconds into an array
my $time = $ARGV[3];
@time = split /:/, $time;
# if the timezone is left out of the input, the position of year becomes 5th in ARGV
my $year = $ARGV[4];

$epoch= timelocal($time[2], $time[1], $time[0], $mday, $mon, $year);
print "$epoch\n";
$ 
$ perl testscr.pl Sun Jul 31 11:58:54 2009
1249055934
$ perl testscr.pl Sun Jul 31 11:58:54
965059134
$ perl testscr.pl Sun Jul 31
965016000
$ perl testscr.pl Sun Jul
Day '' out of range 1..31 at testscr.pl line 25
$ perl testscr.pl Sun
Day '' out of range 1..31 at testscr.pl line 25
$ perl testscr.pl
Day '' out of range 1..31 at testscr.pl line 25
$ 
$ 

tyler_durden