#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2000
    Posts
    1
    Rep Power
    0
    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    15
    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

IMN logo majestic logo spyfu logo threadwatch logo seochat tools logo