次のコードがあります。
#!/usr/bin/perl
use strict;
use warnings;
#use diagnostics;
use URI qw( );
my @insert_words = qw(HELLO GOODBYE);
while (<DATA>) {
chomp;
my $url = URI->new($_);
my $query = $url->query;
foreach (@insert_words) {
# Use package vars to communicate with /(?{})/ blocks.
local our $insert_word = $_;
local our @queries;
if (defined $query) {
$query =~ m{
^(.*[/=])([^/=&]*)((?:[/=&].*)?)\z
(?{
if (length $2) {
push @queries, "$1$insert_word$2$3";
push @queries, "$1$insert_word$3";
push @queries, "$1$2$insert_word$3";
}
})
(?!)
}x;
}
if (@queries) {
for (@queries) {
$url->query($_);
print $url, "\n";
}
}
else {
print $url, "\n";
}
}
}
__DATA__
http://www.example.com/index.php?route=9&other=7
上記のコードは正しく機能し、次の出力が生成されます。
http://www.example.com/index.php?route=9&other=HELLO7
http://www.example.com/index.php?route=9&other=HELLO
http://www.example.com/index.php?route=9&other=7HELLO
http://www.example.com/index.php?route=HELLO9&other=7
http://www.example.com/index.php?route=HELLO&other=7
http://www.example.com/index.php?route=9HELLO&other=7
http://www.example.com/index.php?route=9&other=GOODBYE7
http://www.example.com/index.php?route=9&other=GOODBYE
http://www.example.com/index.php?route=9&other=7GOODBYE
http://www.example.com/index.php?route=GOODBYE9&other=7
http://www.example.com/index.php?route=GOODBYE&other=7
http://www.example.com/index.php?route=9GOODBYE&other=7
ご覧のとおり、URL の特定の場所に配列内の単語が挿入されます。
私が今問題を抱えていること:
HELLO
とGOODBYE
(またはにあるもの)のすべての可能な組み合わせを実行する機能を追加したいと思います。@insert_words
たとえば、既に取得した出力に次の URL も追加する必要があります。
http://www.example.com/index.php?route=HELLO&other=GOODBYE
http://www.example.com/index.php?route=HELLO&other=HELLO
http://www.example.com/index.php?route=GOODBYE&other=HELLO
http://www.example.com/index.php?route=GOODBYE&other=GOODBYE
しかし、これを最善の方法で行う方法がわかりませんか?
これに関するあなたの助けは大歓迎です、どうもありがとう