I need to use the lwp-download program to download multiple files. I took the original lwp-download program included with perl and turned it into a subroutine. I did encounter one error though when I first ran the program. "Variable $shown will not stay shared." This error is referring to the shown variable in the show subroutine at the end of the program. I added a "my" to the shown variable and the error went away.
my $shown++;
However, I don't know if that will create any problems with the rest of the program. To save space on this page I'm only going to post the code that I've added to the lwp-program. You can download the complete program at
http://parasoft.netfirms.com/.
use warnings;
use strict;
# Enter the local directory to save downloaded files into
my $savelocation = "c:\\docume~1\\name\\desktop\\downloads\\";
# If directory does not exist, create it
opendir(FINDDIR, $savelocation) || mkdir($savelocation);
closedir FINDDIR;
# Use the subroutine below for each file you need to download
&getFile("http://www.domainname.com/file.png");
&getFile("http://www.domainname.com/file.txt");
sub getFile {
my $netlocation = $_[0];
my @directories = split(/\//, $netlocation);
my $fname = pop(@directories);
&Download($netlocation, "$savelocation$fname");
}
sub Download {
# the entire lwp-download program
}
There are two problems with the program. It only executes the first getFile subroutine before it exits and it overwrites existing files without prompting. How can I fix this? Thanks.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.