in reply to Subroutine and variable passing

I understand your question, but I'm not really sure what your code is trying to do.

Yet I'll try proposing an alternative solution: Replace it with sprintf?

my $url = [ 2, "/home/user/sym_dir/%s_2013 'http://www.downloadsite.co +m/%s.dat'" ]; get_symbol_data($url); sub get_symbol_data { my ($base_url) = @_; my ($repeats, $fmt_string) = @$base_url; my @sym_array = ('foo', 'bar', 'baz'); for my $symbol (@sym_array) { my $url = sprintf($fmt_string, ( $symbol ) x $repeats); print $url, "\n"; } }

Replies are listed 'Best First'.
Re^2: Subroutine and variable passing
by boftx (Deacon) on Aug 26, 2013 at 05:58 UTC

    I like the approach taken by this proposed solution with one exception: I would forego the $repeats variable and just list $symbol twice in the sprintf argument list. While the former might be more concise, I feel the latter would be more understandable to those who might not be as familiar with the full power of Perl's string processing abilities.