Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 27th, 2012, 11:01 AM
kochaloch's Avatar
kochaloch kochaloch is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 40 kochaloch User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 34 m 15 sec
Reputation Power: 6
Wget with array?

Hi,

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.

Code:
@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.

Thanks!!!

Reply With Quote
  #2  
Old December 27th, 2012, 11:40 AM
keath's Avatar
keath keath is offline
!~ /m$/
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: May 2004
Location: Reno, NV
Posts: 4,085 keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level)keath User rank is General 12nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 4 Days 6 h 51 m 10 sec
Reputation Power: 1809
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:

Code:
#!/usr/bin/perl
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Wget with array?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap