如何在 Perl 中一次输出一屏

发布于 2024-09-03 21:46:38 字数 239 浏览 2 评论 0原文

从命令行执行 Perl 脚本时,如何确保输出不会滚出屏幕?

换句话说,我如何模仿 Unix more更少命令?

When executing a Perl script from the command line, how can I ensure that my output doesn't scroll off the screen?

In other words, how do I mimic the functionality of the Unix more or less commands?

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

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

发布评论

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

评论(4

飞烟轻若梦 2024-09-10 21:46:38

Term::Pager 模块似乎就是您正在寻找的模块。

The Term::Pager module would seem to be what you're looking for.

你的背包 2024-09-10 21:46:38

用户只需将输出传送到less即可。这使他们可以选择使用自己喜欢的寻呼机,或者甚至根本不使用任何寻呼机(如果他们愿意)。

The user can just pipe the output to less. That gives them the option of using their favourite pager, or even not using any pager at all, if they prefer that.

断爱 2024-09-10 21:46:38

正如 Matti Virkkunen 所说 ,用户最好将您的脚本传送到 less

类 Unix 系统的用户希望以纯文本形式输出,因此如果需要,他可以将其传递给其他命令。如果您的脚本不将输出显示为纯文本,您的用户可能会发现您的脚本不太可用。

As Matti Virkkunen says, it's better that the user pipes your script to less.

A user of a Unix-like system would expect output in plain text, so (s)he can pipe it to other commands if they need to. Making your script not displaying output as plain text, your user may find your script less usable.

合久必婚 2024-09-10 21:46:38

对于一种快速而肮脏的方式,您可以将文本通过管道传输到lessmore

my $text = <<'EOD';
Lots
   and
      lots
         of
           text
EOD

my $pager = $ENV{PAGER} || 'less';
open(my $less, '|-', $pager, '-e') || die "Cannot pipe to $pager: $!";
print $less $text;
close($less);

有各种lessmore< /em> 标志允许脚本在到达文本底部时继续。

For a quick-and-dirty way, you can pipe the text to less or more:

my $text = <<'EOD';
Lots
   and
      lots
         of
           text
EOD

my $pager = $ENV{PAGER} || 'less';
open(my $less, '|-', $pager, '-e') || die "Cannot pipe to $pager: $!";
print $less $text;
close($less);

There are various less and more flags to allow the script to continue when it reaches the bottom of the text.

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