in reply to perl daemon

Here is a minor example of something that would work.
#!/usr/bin/perl use strict; ## become a daemon exit if fork(); ## loop and look for a filename appearing my $fn="/homes/bob/important_file.txt"; while (1) { if (-f $fn) { ## a file was found, do something DoSomething(); ## then exit exit; } ## pause 5 minutes before checking again sleep 300; } ## never here! exit;

Replies are listed 'Best First'.
Re: Re: perl daemon
by eLore (Hermit) on Feb 08, 2001 at 19:19 UTC
    mr.nick: shouldn't
    while (1) { if (-f $fn) { ## a file was found, do something DoSomething(); ## then exit exit; } ## pause 5 minutes before checking again sleep 300; }

    really be:

    while (1) { if (-f $fn) { ## a file was found, do something DoSomething(); ## then break the loop break; ## <<-- not exit(); } ## pause 5 minutes before checking again sleep 300; }
      exit is fine here: it exits the program. There is no 'break' in Perl, but there is a last, which does the same thing. I would have used 'last' myself as well, but 'exit' works fine.