-4

Perl 有没有办法随机化所有参数,例如:

http://s.example.com/x?list=hahaha&a=&b=&c=&1

所以所有带有&a=&b=&c=&1 etc.etc.etc的参数。

这是我期望的输出?

for (1..10){

#random this http://s.example.com/x?list=hahaha&a=&b=&c=&1
#to be like this


print "\n";
#http://s.example.com/x?list=hahaha&b=&a=&c=&1
#http://s.example.com/x?list=hahaha&c=&a=&b=&1
##http://s.example.com/x?list=hahaha&1=&b=&1=&c

}

那么有人可以帮忙吗?

Thnx 已经准备好了

4

1 回答 1

1

您提供的信息不多,但这里有一个(非常简单的)方法可以帮助您入门。

代码

#!/usr/bin/env perl

use strict;
use warnings;
use feature 'say';
use URI;
use URI::QueryParam;

# prepare
my @all  = map {chr $_} 32 .. 126;
my @word = grep /\w/ => @all;

# randomization helpers
sub rand_number      { 1 + rand 10 }
sub rand_param_name  { join '' => map {$word[rand @word]} 1 .. rand_number }
sub rand_param_value { join '' => map {$all[rand @all]}   1 .. rand_number }

# create three uris with randomized parameters
for (1 .. 3) {

    # prepare
    my $uri = URI->new('http://s.example.com/x');

    # add randomized parameters
    $uri->query_param(rand_param_name() => rand_param_value)
        for 1 .. rand_number;

    # done
    say $uri;
}

输出

http://s.example.com/x?TC10=MX3+B_i!
http://s.example.com/x?BaXgf=%26%7BY%5Dxt%25o&l0f=HM%5Cd%24JB%3E)&lDQ7a94=Xh%3AB3N1jK_&dzGNz3=Y8NX4o9%5BS&YnCMxDdTew=J%5B%7B~b%23&Mr8UpMhPo=H&8_nAwh8ZHe=9%5DRY%40V&EgheAy='Uk&gmqTwKW=7PyitIn&3=V%5EKApdS%2C
http://s.example.com/x?dBA7WswJ5=GX-x&yKHeb=1y1sq%3EjPt&7G=7oa%24XF%7C)jQ&FjVo5IpF=%3BZ%5C&JB7OLer=%7C55&bYo64Fiy=L%23%40&ZhSohJVZ=-W+Rp5c+%5DD&aP=zJP%7Bu&pE5URXCWq=PHZJ%60%3D97L&6Xw7Da7=.Drb
于 2012-09-27T10:26:26.680 回答