在bash中,序列号例如222R5555
echo {0..9}{0..9}{0..9}{A..Z}{0..9}{0..9}{0..9}{0..9} > seqList.txt
在Perl中可以缩短(减少代码)吗?有没有办法在perl的范围内使用repeat运算符?
由于
答案 0 :(得分:6)
用更少的代码?不会.Perl的字符串增量不允许数字位于字母之前,因此您必须将其分为两个范围:'000' .. '999'
和'A0000' .. 'Z9999'
并连接值。这肯定会超过68个字符的代码。
答案 1 :(得分:4)
my $g0to9 = '{'.join(',', '0'..'9').'}';
my $gAtoZ = '{'.join(',', 'A'..'Z').'}';
my %glob = join('', $g0to9 x 3, $gAtoZ, $g0to9 x 4);
while (my $_ = glob($glob)) {
...
}
或
[ Deleted ]
或
for my $p1 ('000'..'999') {
for my $p2 ('A0000'..'Z9999') {
my $_ = "$p1$p2";
...
}
}
或
for my $ch0 ('0'..'9') {
for my $ch1 ('0'..'9') {
for my $ch2 ('0'..'9') {
for my $ch3 ('A'..'Z') {
for my $ch4 ('0'..'9') {
for my $ch5 ('0'..'9') {
for my $ch6 ('0'..'9') {
for my $ch7 ('0'..'9') {
my $_ = join '', $ch0, $ch1, $ch2, $ch3, $ch4, $ch5, $ch6, $ch7;
...
}}}}}}}}
或
use Algorithm::Loops qw( NestedLoops );
my $i = NestedLoops([
(['0'..'9'])x3,
(['A'..'Z']),
(['0'..'9'])x4,
]);
while (my @chs = $i->()) {
my $_ = join '', @chs;
...
}