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


In reply to Re: Subroutine and variable passing by kcott
in thread Subroutine and variable passing by tman77

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.