嗨,我目前正在使用 List::Util shuffle 用 CGI 随机化一个数组,但是我想修改代码以使用 rand 代替
这是我的代码
print "Content-type: text/html\n\n";
use List::Util qw(shuffle);
@haikuone = ('behind', 'the', 'red', 'barn');
@haikutwo = ('prairie', 'grasses', 'reclaiming');
@haikuthree = ('the', 'basketball', 'court');
@randomize1 = shuffle(@haikuone);
@randomize2 = shuffle(@haikutwo);
@randomize3 = shuffle(@haikuthree);
print "<html>\n";
print "<head><title>Haiku_Random</title></head>\n";
print "<body>\n";
print "<pre>\n";
print "RANDOM HAIKU (DISCLAIMER: NONSENSE MAY OCCUR)\n";
print "@randomize1\n";
print "@randomize2\n";
print "@randomize3\n";
我将如何修改此代码以使用 rand 而不是 List::Util
我认为它不多,但这里是新手
我正在努力让这个工作
$haikuone = ('behind', 'the', 'red', 'barn');
$haikutwo = ('prairie', 'grasses', 'reclaiming');
$haikuthree = ('the', 'basketball', 'court');
@random1 = $line1[rand @haikuone];
@random2 = $line2[rand @haikutwo];
@random3 = $line3[rand @haikuthree];
print "RANDOM HAIKU (DISCLAIMER: NONSENSE MAY OCCUR)\n";
print "$line1\n";
现在当我这样做时
#!/usr/local/bin/perl
@haikuone = ('behind', 'the', 'red', 'barn');
@haikutwo = ('prairie', 'grasses', 'reclaiming');
@haikuthree = ('the', 'basketball', 'court');
@random1 = $line1[rand @haikuone];
@random2 = $line2[rand @haikutwo];
@random3 = $line3[rand @haikuthree];
print "RANDOM HAIKU (DISCLAIMER: NONSENSE MAY OCCUR)\n";
print "@haikuone\n";
它会打印haikuone,但不会随机化