in reply to Subroutine and variable passing
G'day tman77,
Welcome to the monastery.
Had you been using strict, you would've received a strict vars error explaining the problem. ${symbol} is neither declared nor defined so $wget_url evaluates to:
"/home/user/sym_dir/_2013 'http://www.downloadsite.com/.dat'"
Had you declared, but not defined, ${symbol}, Perl would've warned you of that as well, if you'd been using warnings. So, unless you have a very good reason not to, always put
use strict; use wanings;
at the start of your code. Typing those few characters and being advised immediately by Perl of problems with your code is obviously a lot less work than having to post a question in a forum; and, also obviously, the feedback is a lot quicker.
I don't think your approach to this is a particularly good one; although, without knowing more about the context of your complete code, it's difficult to specifically advise what would be better. I'd probably have used some sort of token in place of ${symbol} and substituted that with the symbols from the file; something along these lines:
$ perl -Mstrict -Mwarnings -le ' my $wget_url = "/some/path/_SYMBOL__2013 http://example.com/_SYMBO +L_.dat"; my @symbols = qw{A B C}; for (@symbols) { (my $sym_url = $wget_url) =~ s/_SYMBOL_/$_/g; print $sym_url; } ' /some/path/A_2013 http://example.com/A.dat /some/path/B_2013 http://example.com/B.dat /some/path/C_2013 http://example.com/C.dat
A few other issues with your code:
-- Ken
|
|---|