|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
1200+ fellow developers rate and compare features of the top IDEs, like Visual Studio, Eclipse, RAD, Delphi and others, across 13 categories. Enjoy this FREE Download of the IDE User Satisfaction Study by Evans Data Corporation. Download Now!
|
|
#1
|
|||
|
|||
|
I have been working on a little alarm clock script just to try and introduce myself to perl. I am almost done now, but I am having problems with one part. The program doesn't seem to want to advance through an array of alarm times so that it is set for the correct time. I'll show you the problem causing code here:
sub setAlarmDay { &updateDate; ($alarm_day_week,$alarm_hour,$alarm_minute) = split /:/, $alarm_times[$array_counter]; if ($day_week == $alarm_day_week) { &setAlarmHour; } else { $array_counter=$array_counter+1; if ($array_counter > 6) { $array_counter=0; } &setAlarmDay; } } sub setAlarmHour { if ($hour >= $alarm_hour && $minute >= $alarm_minute) { $array_counter=$array_counter+1; ($alarm_day_week,$alarm_hour,$alarm_minute) = split /:/, $alarm_times[$array_counter]; &setAlarmDay; } else { print "alarm set to: day: $alarm_day_week hour: $alarm_hour minute: $alarm_minuten"; &checkDay; } } sub updateDate { $date=`/bin/date`; ($day_week,$month,$day,$time,$time_zone,$year) = split / /, $date; ($hour,$minute,$second) = split /:/, $time; } @days_week=("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); @alarm_times=("Mon:06:30", "Tue:07:30", "Wed:08:30", "Thu:00:12", "Fri:08:30", "Sat:11:00", "Sun:10:00"); I hope that is enough. The script seems to get stuck on Monday because the array_counter is initialized to 0. I would appreciate any suggestions. |
|
#2
|
|||
|
|||
|
I have one question:
Why don't you change this: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR> if ($array_counter > 6) { $array_counter=0; } [/quote] by this: <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR> if ($array_counter > 6) { $array_counter=$array_counter%6; } [/quote] And I have one suggestion. Try a foreach loop. ------------------ Good luck, Bas ------------------ E-mail me at: b.vandermeijden@pecoma.nl |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > Fairly simple problem.....I hope! |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|