学习Perl-Perl教程 [英] Learning Perl - Perl Tutorial

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

问题描述

你好,
我决定学习一些Perl,并通过Nik Silver找到了本教程: http://www.comp.leeds.ac. uk/Perl/ [ ^ ].在控制结构练习中,我解决了第一部分:在每行之前放置一个行号,但是我不知道如何解决第二部分:在前面放置一个3位数字每行.  有人有什么想法吗?


真诚的
Mike

Hello,
I decided to learn some Perl and I found this tutorial by Nik Silver: http://www.comp.leeds.ac.uk/Perl/[^].  In the Control Structures exercise, I solved the first part: putting a line number before each line, but I don''t know how to solve the second part: putting a 3-digit number before each line.  Does anyone have any ideas?


Sincerely,
Mike

推荐答案

如果您可以展示尝试过的方法,那会很好,但是如果没有这样做,我想您可能需要做的只是查找,并使用%03d之类的格式.假设您已经安装了不错的Perl,使用perldoc -f sprintf应该可以在命令行中找到所需的所有内容.请注意,sprintfprintf使用相同的格式代码,如果您完全了解C,他们应该非常熟悉.

一种替代方法是使用Perl的format工具,该工具功能非常强大,但在当今的HTML等中几乎未使用.过去,我已经使用它进行了一些漂亮的文本格式化,以生成报告,如果您使用的是简单文本,则可能值得一看.

欢呼!
Don
It would be good if you would show what you have tried, but in absence of that, I think all you likely need to do is look up printf, and use a format like %03d. Assuming you have a decent Perl installation, you should be able to find out all you need at the command line with perldoc -f sprintf. Note that sprintf and printf use the same formatting codes, and if you know C at all they should be very familiar.

An alternative would be to use Perl''s format facility which is quite powerful, but mostly unused in these days of HTML and so on. I have done some pretty fancy text formatting with it in the past for report generation, and if you''re working in simple text it may be worth a look.

cheers!
Don


这里是一个打印行号的程序:

Here is a program that prints line numbers:


file =``results.log'';
打开(INFO,
file = ''results.log'';
open(INFO,


这篇关于学习Perl-Perl教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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