in reply to Re^2: Execute on conditional check
in thread Execute on conditional check

This looks very much like a shell script. Shell scripts are not Perl. Please rewrite your shell script as a Perl script or ask your question elsewhere.

Replies are listed 'Best First'.
Re^4: Execute on conditional check
by Anonymous Monk on Jun 20, 2010 at 15:32 UTC
    I am sorry.
    while () { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime t +ime; $time_val="$hour:$min:$sec"; while ($time_val == "08:28:00") { print "1st loop\n"; } while ($time_val == "08:28:30") { print "2nd loop\n"; } }
    What is the problem in this script. I am writing the while loop recursivley, so that even for the next day it will execute checking on the condition.
    But now this code doesn't work.
    When the first condition is true, then it should print "1st loop" and execute the second while loop

      If you want to write something like cron, see Schedule::Cron.

      Other than that, have you printed out your $time_val to debug it? It does not contain what you think it does. And even if it contains what you think it does, == is not the comparison operator to use for strings. See perlop for the comparison operator for strings.

      change
      while ($time_val == "08:28:00") {
      to
      if ($time_val eq "08:28:00") {
      Update: (thanks to Perlbotics)

      also change

      $time_val="$hour:$min:$sec";
      to
      $time_val=sprintf("%02d:%02d:%02d", $hour, $min ,$sec);
      Then all values smaller than 10 will be formatted with two digits.