Perl:打印回行首 [英] Perl: print back to beginning of line

查看:48
本文介绍了Perl:打印回行首的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,所以我想要做的是打印出一个完整的百分比到我的命令行,现在,我想简单地更新"屏幕上显示的数字.所以以某种方式回到行首并更改它.

Okay, so what I'm trying to do is print out a percentage complete to my command line, now, I would like this to simply 'update' the number shown on the screen. So somehow go back to the beginning of the line and change it.

例如,windows relog.exe 命令行实用程序(可以将 .blg 文件转换为 .csv 文件)执行此操作.如果你运行它,它会显示一个完成的百分比.

For example the windows relog.exe command-line utility (which can convert a .blg file to a .csv file) does this. If you run it, it will display a percentage complete.

现在这可能是用 C++ 编写的.我不知道这在 perl 中是否也可能?

Now this is probably written in C++. I don't know if this is possible in perl as well ?

推荐答案

使用 "或15"八进制(又名Return caret"又名回车" 字符源自打字机时代:)

Use " " or "15" octal (aka "Return caret" aka "Carriage Return" character originating from typewriter days :)

> perl5.8 -e 'print "11111
222
3
";'
32211
> perl5.8 -e 'print "1111115222153
";'  
32211

不要忘记打印至少与已打印的最长字符串一样多的字符以覆盖任何旧字符(如您在上面的示例中所见,不这样做将保留旧字符).

Just don't forget to print at least as many characters as the longest string already printed to overwrite any old characters (as you can see in example above, the failure to do so will keep old characters).

另一件需要注意的事情是,正如 Michael 在评论中指出的那样,在这些打印发生时需要打开自动刷新,以便输出不会在处理的最后等待换行符.

Another thing to be aware of is, as Michael pointed in the commment, the autoflush needs to be turned on while these printings happen, so that the output doesn't wait for newline character at the very end of the processing.

更新:请注意,另一个答案中推荐的 013 八进制字符实际上是一个垂直制表符:

UPDATE: Please note that 013 octal character recommended in another answer is actually a Vertical Tab:

> perl5.8 -e 'print "1111113222133
";'    
11111
     222
        3

这篇关于Perl:打印回行首的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆