Question

I have the following piece of code:

use strict;
use warnings;
use URI;
use URI::QueryParam;

open (URLS, "<urls.txt");
open (EXTRAPARAMS, "<extraparams.txt");

my @words = (<EXTRAPARAMS>);  

while ( my $URL = <URLS>) {
        my $uri = URI->new($URL);
        print "GETS THIS FAR\n";
        print "$uri\n";

    for my $key ($uri->query_param) {
         print "CANT GET HERE\n";                        #why does it not get here?
         my $org = $uri->query_param($key);
         for my $word (@words) {
             for ("$org$word", $word, "$word$org") {
                 $uri->query_param($key, $_);
                 print $uri->as_string, $/;
             }
         }
         $uri->query_param($key, $org);
    }
}

The problem I am having

I am able to read in each of the urls from the URLS text file and print them, but i cannot seem to enter the for loop for some reason.

Is there something obvious I am overlooking or not doing because I cant seem to work out why its not getting there?

It may be nothing to do with the URI::QueryParam stuff and just an error I have made but I cant find it.

I have looked at the docs for URI::QueryParam and everything appears to be written/formatted how it should be as far as the $key and query_param parts are concerned as far as I can see, so I don't know whats wrong?

Your help is much appreciated, many thanks

Was it helpful?

Solution

This simplification of your code works fine:

use strict;
use warnings;
use URI;
use URI::QueryParam;

my $uri = URI->new("http://www.foo.com?bar=baz&sproing=blargh");

for my $key ($uri->query_param) {
     print "$key\n";
}

Output:

bar
sproing

The problem is almost certainly with your data: your URL isn't correctly formatted or doesn't have any parameters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top