Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

creating a list of url's with one changing variable 3

Status
Not open for further replies.

torstens

Technical User
Oct 9, 2006
26
0
0
US
I'm trying to create a search by constructing the resulting url(s). In order to do so I have a base url string

$url = blah.com/sassafras%

this would be the first page, and the subsequent search pages would be...

blah.com/sassafras%&ct=11
blah.com/sassafras%&ct=21
blah.com/sassafras%&ct=31
...

How can I creat a line of code that adds a variable with increasing values into the url for 11, 21, 31... and place them in a list

How would I go about stopping the list creation once there are no longer any corresponding pages (i.e. there are no more result pages)
 
>> How would I go about stopping the list creation once there are no longer any corresponding pages (i.e. there are no more result pages)

Depends on how your script is fetching the results.

- Kevin, perl coder unexceptional!
 
how bout if I want to populate a list of 100. Meaning, I want 100 urls following the pattern above.
 
Code:
$a=11;
while ($a<= 1100){
  push (@array,"blah.com/sassafras&ct=$a");
  $a += 10;
}
or
Code:
push (@array,"blah.com/sassafras&ct=$_") foreach (1 .. 100);

Something like that?
 
I wouldn't use $a (or $b) since they are special variables used by perl for sorting, but BrianAtWork has the basic method correct. Another way could be:

Code:
my $n = 1;
my @urls = ();
$urls[$_] = "blah.com/sassafras%&ct=@{[$n+=10]}" for (0..99);








- Kevin, perl coder unexceptional!
 
Heh heh... Very true - I usually use variable names that are a bit more descriptive...

I like your [$n+=10] method though - that is pretty slick!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top