perl单线将一组序列放在一个块中处理

发布于 2025-02-12 01:08:34 字数 324 浏览 1 评论 0原文

如何将一组序列放在其超集组中的一组序列,在一个代码中处理

任务失败:

$ for i in {1..9} ;{ echo $i ;} |perl -pe 'my $s; if (/3/) {  while(1) { $s .= $_; print $s; last if (/7/) }  } '

使用perl -pe -pe option do option do do ofting oft ofting oft OF String行的输出:

1
2
3
4567
8
9

How Perl one-liner for herding a group of sequences, out of its superset group, to be processed in a block of codes

The task fail done:

$ for i in {1..9} ;{ echo $i ;} |perl -pe 'my $s; if (/3/) {  while(1) { $s .= $_; print $s; last if (/7/) }  } '

to use Perl -pe option do output of string lines of:

1
2
3
4567
8
9

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

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

发布评论

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

评论(1

梦萦几度 2025-02-19 01:08:34

使用此perl单线:

for i in `seq 9` ; do echo $i; done | \
    perl -lne 'if ($_ == 3 .. $_ == 7) { push @a, $_; print @a if $_ == 7; next; } print;'
1
2
34567
8
9

perl单线使用以下命令行标志:
-e:告诉Perl在线寻找代码,而不是在文件中。
-n:一次循环一行,将其分配给$ _默认情况下。
-l <​​/code>:在 *nix上( nix)上剥离输入行分隔符(“ \ n”),然后再执行代码在线执行代码,并在打印时将其附加。

另请参见:
perldoc perlrun

Use this Perl one-liner:

for i in `seq 9` ; do echo $i; done | \
    perl -lne 'if ($_ == 3 .. $_ == 7) { push @a, $_; print @a if $_ == 7; next; } print;'
1
2
34567
8
9

The Perl one-liner uses these command line flags:
-e : Tells Perl to look for code in-line, instead of in a file.
-n : Loop over the input one line at a time, assigning it to $_ by default.
-l : Strip the input line separator ("\n" on *NIX by default) before executing the code in-line, and append it when printing.

SEE ALSO:
perldoc perlrun: how to execute the Perl interpreter: command line switches

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