Perl 序列号生成器

发布于 2024-11-07 06:53:20 字数 198 浏览 0 评论 0原文

在 bash 中,序列号例如 222R5555

echo {0..9}{0..9}{0..9}{A..Z}{0..9}{0..9}{0..9}{0..9}  > seqList.txt

在 perl 中该行可以做得更短(更少的代码)吗?有没有办法在 perl 中的范围内使用重复运算符?

谢谢

In bash, sequence numbers e.g. 222R5555

echo {0..9}{0..9}{0..9}{A..Z}{0..9}{0..9}{0..9}{0..9}  > seqList.txt

Can that line be done shorter (less code) in perl? Is there a way to use the repeat operator on ranges in perl?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

霓裳挽歌倾城醉 2024-11-14 06:53:21
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;
   ...
}
my $g0to9 = '{'.join(',', '0'..'9').'}';
my $gAtoZ = '{'.join(',', 'A'..'Z').'}';
my %glob = join('', $g0to9 x 3, $gAtoZ, $g0to9 x 4);
while (my $_ = glob($glob)) {
   ...
}

or

[ Deleted ]

or

for my $p1 ('000'..'999') {
   for my $p2 ('A0000'..'Z9999') {
      my $_ = "$p1$p2";
      ...
   }
}

or

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;
   ...
}}}}}}}}

or

use Algorithm::Loops qw( NestedLoops );
my $i = NestedLoops([
   (['0'..'9'])x3,
   (['A'..'Z']),
   (['0'..'9'])x4,
]);
while (my @chs = $i->()) {
   my $_ = join '', @chs;
   ...
}
北渚 2024-11-14 06:53:20

用更少的代码?不可以。Perl 的字符串增量不允许数字位于字母之前,因此您必须将其分成两个范围: '000' .. '999''A0000' 。 . 'Z9999' 并连接这些值。这肯定需要超过 68 个字符的代码。

With less code? No. Perl's string increment doesn't allow digits to precede letters, so you'd have to break it up into two ranges: '000' .. '999' and 'A0000' .. 'Z9999' and concatenate the values. That's certainly going to take more than 68 characters of code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文