in reply to lwp-download program

There are two basic ways to check whether a file exists before clobbering it. You can use stat or its little cousin -e on the filename before opening, or else you can call sysopen with the O_EXCL flag set and catch the error when the file exists.

As near as I can see, lwp-download is a one-shot program not designed for downloading multiple files. In your wrapper, you could accept a list of urls from the command line and loop through calls to lwp-download. I don't know why you are getting only one getFile() call through unless you are hitting some fatal error in the first call.

Why don't you just call lwp-download through system instead of pasting it into a subroutine? I'm very suspicious of that procedure, there are lots of traps you can trip doing that.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re^2: lwp-download program
by pccode (Novice) on May 29, 2005 at 20:24 UTC
    The lwp-download script actually checks for existing files and then prompts you before it overwrites them. Unfortunately that part of the program stopped working in the download subroutine.
    # Check if the file is already present if (-f $file && -t) { $shown = 1; print "Overwrite $file? [y] "; my $ans = <STDIN>; unless (defined($ans) && $ans =~ /^y?\n/) + { if (defined $ans) { print "Ok, aborting.\n"; } else { print "\nAborting.\n"; } exit 1; } $shown = 0; } else { print "Saving to '$file'...\n"; }
    I will try your suggestion to use system instead of the subroutine.
      The system function solves the problem. Thanks.