in reply to Getting a script to re-run itself

While its probably better to wrap the whole thing in a while loop, and put something like this in the loop:
last if $all_done;

Another idea would be to just put this at the end of the script:

exec '/my/script' unless $all_done;

Replies are listed 'Best First'.
Re: Re: Getting a script to re-run itself
by mr.nick (Chaplain) on Jun 26, 2001 at 02:10 UTC
    Even better would be to use $0 as the parameter to exec.
    exec $0 unless $all_done;
    That way the script can move around on the filesystem and you won't need to hand edit it.

    A warning: the above doesn't work correctly under Windows. For some reason, exec $0 spawns another copy of your script in the background. If you write a small test program like:

    print "hi!\n"; sleep 2; exec $0;
    and run it, you get the effect of:
    H:\>test.pl hi! hi! H:\>hi! hi! hi!
    What exactly it is doing, I don't know :)

    mr.nick ...