1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2008
    Rep Power

    Wget with array?


    I have a cgi perl script and I'm trying to use wget with an array in the address, but it is not interpreting the array. I checked the logs and it executing the wget with http://someaddress=@array[$i] instead of "http://someaddress=111,222,333,444,555.

    @array[0] = 111,222,333,444,555;
    for ($i = 0; $i<$as; ++$i){
    system ('wget "http://someaddress=@array[$i]"');
    if i hard code the values in it works fine but that is not an option.

    Im still very new to perl, so if anyone could help it would be greatly appreciated.

  2. #2
  3. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Reno, NV
    Rep Power
    There are a couple of problems. Your syntax for creating an array is incorrect. The other problem has to do with quoting strings.

    Perl has several constructs for quoting and building strings. When you use single quotes on the outer part of a string, you are telling perl to use the string literally. No variables will be interpolated, so that's why you saw what you did. You need outer double quotes, or use the qq// notation:

    use strict;
    use warnings;
    use Data::Dumper;
    my @array = (111,222,333,444,555);
    print Dumper \@array;
    foreach my $parameter (@array){
    	my $command_string = qq{wget "http://someaddress=$parameter"};
    	print "$command_string\n";
    	system ($command_string);
    Also worth noting that perl has the LWP library to make web requests directly from perl. No need to use the system or the wget command.

    Comments on this post

    • kochaloch agrees : Thanks

IMN logo majestic logo threadwatch logo seochat tools logo