StormMedic85
Programmer
Below is my current code. I have the user enter a year, month, date and time. What I'd like to do is consolidate this all into one line...the user can enter it in a certain format like YYYYMMDDTT and the program will extract the year, month, and date from what's entered and format it the same way I have it below.
The formatting is important. For example, if the user were to just enter 9 for the month and not 09 I would want the program to format it appropriately. Any suggestions and help would be greatly appreciated!
Here's how I have it currently...
#!/usr/local/bin/perl -w
print "Enter the four digit year: ";
$year = <STDIN>;
chomp $year;
print "Enter the number of the month: ";
$month = <STDIN>;
chomp $month;
print "Enter the date: ";
$date = <STDIN>;
chomp $date;
print "Enter the sounding time (1200 or 0000): ";
$time = <STDIN>;
chomp $time;
$RAMSDate=sprintf("%04d-%02d-%02d-%04d",$year,$month,$date,$time);
$NWSDate=sprintf("%04d%02d%02d%04d",$year,$month,$date,$time);
print "$RAMSDate \n";
print "$NWSDate \n";
The formatting is important. For example, if the user were to just enter 9 for the month and not 09 I would want the program to format it appropriately. Any suggestions and help would be greatly appreciated!
Here's how I have it currently...
#!/usr/local/bin/perl -w
print "Enter the four digit year: ";
$year = <STDIN>;
chomp $year;
print "Enter the number of the month: ";
$month = <STDIN>;
chomp $month;
print "Enter the date: ";
$date = <STDIN>;
chomp $date;
print "Enter the sounding time (1200 or 0000): ";
$time = <STDIN>;
chomp $time;
$RAMSDate=sprintf("%04d-%02d-%02d-%04d",$year,$month,$date,$time);
$NWSDate=sprintf("%04d%02d%02d%04d",$year,$month,$date,$time);
print "$RAMSDate \n";
print "$NWSDate \n";