I have a perl script which prints me the epoch value of a specific date and time given.Now I want to proceed to a next step ie i want to give the input at the time of execution.
I have to initialise the date and time values in the script before executing it.But now i want to give the date as input during executing the script so that the script prints me the epoch time of any date i give.
Can someone please suggest me in getting this.
My code looks as below:
#!/usr/bin/perl
use Time::Local ;
$sec=00;
$min=01;
$hours=00;
$day=1;
$month=0;
$year=110;
$Beg_time = (timelocal($sec,$min,$hours,$day,$month,$year) * 1000);
print "Epoch Beg Value: $Beg_time\n";
Thanks for the reply.
But iam little confused as of how to use the code.
Iam using the code in the below way.But when i run it iam not asked for any input.
Hope u find something which iam missing.
$date=<>;
my ($sec,$min,$hour,$day,$month,$year) = split(/:/,<>);
print "hour is $hour\n";
Hi Jyothi , <> is a kind of input reader . DO NOT use it twice here with $date=<> and the next line. Then you are entering the date twice and with -w switch you will be notified that main::date is getting used only once. So remove the line
$date=<> or comment it. I already specified an OR in the two statements.
So you statement would be like
my ($sec,$min,$hour,$day,$month,$year) = split(/:/,<>);
print "hour is $hour\n";
At the prompt you enter the date as ->44:23:05:22:08:09
Note the fields delimited by colons.
and you get the output.