Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date and Time

Status
Not open for further replies.

tchatzi

Technical User
Dec 15, 2004
744
0
0
GR
i just wrote this lines

#!/usr/bin/perl -w
use warnings;
my $dnow = `date`;
my $tnow = `time`;
print "$dnow, $tnow";

and i was waitting to get the date and the time when i run it, but the thing is that the program waits for me to press 'return' button two times and then it gives me the date and the time like this

The current date is: Fri 12/17/2004
Enter the new date: (mm-dd-yy) , The current time is: 9:02:45.20
Enter the new time:
C:\Documents and Settings\Pengo\My Documents\Perl Code>

what did i do wrong?
 
fauls alarm i got what was wrong,
in msdos to get you the time and the date without the prompt for entering a new one is '/T'
so it is
my $dnow = `date/T`;
my $tnow = `time/T`;

but why did the program waited for the 'enter' and for two times before it shows me the date, the time and the prompt?
 
As you said, on msdos, the command [tt]date[/tt] and [tt]time[/tt] without arguments let you change the date and time. Each of them expected you (so waited for you) to enter a new date or time and to press return to validate. No surprise then.

--------------------

Denis
 
You'd be better off using perl's functions, as it makes things more cross-platform. To get a decent human-readable date/time printout, do this:
Code:
my $datetime = localtime time;

If you want to print that directly, you have to ensure it's evaluated in a scalar context, otherwise the output will be pretty unintelligable:
Code:
print scalar localtime time;
 
thank you all for the tips,
a new thread is comming up
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top