使用perl脚本获取字符串中所有可能的单词排列

zey*_*zey 0 perl permutation cpu-word

我有一个像这样的字符串how are you,我希望得到所有可能的字样

how are you
are how you
you how are
you are how
are you how
how you are
Run Code Online (Sandbox Code Playgroud)

如何在perl脚本中创建它,我已经尝试了该shuffle函数,但它只返回一个shuffle字符串.
如果您不熟悉Perl脚本,则只能告诉我逻辑.

注意:字符串中的字数不是常量.

bgo*_*dst 5

你所说的是排列.这可以在Perl中使用Algorithm::Permute模块完成:

如果你已经安装了模块,这里有一个shell one-liner,可以为你做到:

perl -e'
 use Algorithm::Permute qw();
 my $str = $ARGV[0]; 
 my @arr = split(/\s+/,$str);
 my $ap = new Algorithm::Permute(\@arr); 
 while (my @res = $ap->next()) { print("@res\n"); }
' 'how are you';
## you are how
## are you how
## are how you
## you how are
## how you are
## how are you
Run Code Online (Sandbox Code Playgroud)