Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2002
    Posts
    1

    Unanswered: I'm sure you've seen this before, but....Unitialized Value/Cron

    All,
    First off, would anybody know why a script gives differernt results when from a cron job then from the command line? (That's one of my problems, maybe it will be corrected if I fix the problem below.)

    As I'm sure you've all read and fixed a thousand times before, I'm having a 'Use of initialized value at line #" error after running my program (again from the cron, not from the command line). The code around the error is as follows:
    -----------------
    @file_list = qw(file1 file2 file3);
    foreach $file (@file_list) {
    $count = `grep "<a string>" $file | wc -l`;
    if ($count eq " 0 ") {
    system (echo "no matches in $file" >> another_file);
    } else {
    system (echo "$count matches found in $file >> another_file);
    }
    }
    }
    -------------------
    I'm getting the "unitialized value" error on the 3rd line of the above code AFTER the first foreach loop. When I run the script from the command line, it correctly writes "# matches found in file" but from the cron, it incorrectly writes "no matches found". BTW, I'm not using any "use" or "my" statements before/after this block.

    Any ideas?

  2. #2
    Join Date
    Sep 2002
    Location
    Germany, near Aachen
    Posts
    120

    Re: I'm sure you've seen this before, but....Unitialized Value/Cron

    > First off, would anybody know why a script gives
    > differernt results when from a cron job then from the
    > command line? (That's one of my problems, maybe it
    > will be corrected if I fix the problem below.)

    A cron job has a different environment. You have to specify programs with their full path, for instance.

    > The code around the error is as follows:

    Code:
    @file_list = qw(file1 file2 file3);
      foreach $file (@file_list) {
         $count = `grep "<a string>" $file | wc -l`;
          if ($count eq "              0 ") {
             system (echo "no matches in $file" >> another_file);
           } else {
             system (echo "$count matches found in $file >> another_file);
           }
          }
       }
    > Any ideas?

    It's not easy to find an error in a piece of made-up perl.
    Some thoughts:
    - Strip the program down to the smallest running piece of code.
    - From your code it looks like you are not using 'strict'. Use it!
    - Consider visiting www.perlmonks.org.
    rgds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •