とりあえず書いただけなのでバグだらけかも
!/usr/bin/perl use strict; use warnings; open(FILE,"<input.ctl"); my @lines = <FILE>; foreach my $line (@lines) { if ($line =~ m/tdef/) { chomp($line); my @tdef = split(' ',$line); print 'number of times= ',"$tdef[1]\n"; print 'start time= ',"$tdef[3]\n"; print 'time interval= ',"$tdef[4]\n"; my $hour = substr($tdef[3],0,2); my $day = substr($tdef[3],3,2); my $month = substr($tdef[3],5,3); #Convert month----------------------------- if ($month eq 'JAN') { $month = '01'; } elsif ($month eq 'FEB') { $month = '02'; } elsif ($month eq 'MAR') { $month = '03'; } elsif ($month eq 'APR') { $month = '04'; } elsif ($month eq 'MAY') { $month = '05'; } elsif ($month eq 'JUN') { $month = '06'; } elsif ($month eq 'JUL') { $month = '07'; } elsif ($month eq 'AUG') { $month = '08'; } elsif ($month eq 'SEP') { $month = '09'; } elsif ($month eq 'OCT') { $month = '10'; } elsif ($month eq 'NOV') { $month = '11'; } elsif ($month eq 'DEC') { $month = '12'; } #---------------------------------------- my $year = substr($tdef[3],8,4); #user input start and end time------------------ Time_input: print "\n"; print "Input time (ex.2010 08 11 00)\n"; my $start = <STDIN>; my @time_usr = split(' ',$start); #----------------------------------------------- #calculation of T for grads--------------------- if ($time_usr[0] < $year or ($time_usr[0] == $year and $time_usr[1] < $month) or ($time_usr[0] == $year and $time_usr[1] == $month and $time_usr[2] < $day) or ($time_usr[0] == $year and $time_usr[1] == $month and $time_usr[2] == $day and $time_usr[3] < $hour)) { print "out of data period (too early)!!!!\n"; goto Time_input; } if ($time_usr[0] ne $year or $time_usr[1] ne $month) { print "Year and month variations are not supported yet\n"; goto Time_input; } my $d_day=$time_usr[2] - $day; my $d_hour=$time_usr[3] - $hour; my $sum_hour=($d_day * 24) + $d_hour; if ($tdef[4] eq '60MN') { $tdef[4] = 1; } else { $tdef[4] =~ s/HR//g; } my $t_inc=1+($sum_hour / $tdef[4]); if ($t_inc > $tdef[1]) { print "out of data period (too late)!!!!\n"; goto Time_input; } #----------------------------------------------- print "$t_inc\n"; goto Time_input; } }