在《作业》博文系列开始前,先来个前言。
《小骆驼书》是什么?就是那本很有名的《Perl语言入门》了。
作业是什么?就是那本书后面的习题了。
1 【7】键入前面的"Hello, world"程序,想办法让它运行起来!
#!/usr/bin/perl
print "Hello, World! \n";
我的系统是Window XP,以上的perl程序要在我的系统上运行起来,有两种办法:
×使用cygwin平台,在cygwin上安装Perl编译器等个程序,具体过程与本站以前配置gcc的过程类似,请参考http://www.51testing.com/?10851/action_viewspace_itemid_81658.html
×安装ActivePerl for MSWin32的版本,也可以在windows配置perl的环境。
我用的是第一种cygwin环境的perl编译器。编写代码用的编辑器,我选择的是UltraEdit,只要把perl代码保存成以.pl为扩展名,UltraEdit即可用不同颜色显示不同的语法,很好用。IDE?我还不知道有专门用于perl开发的IDE。
2 【5】在命令行提示符后键入perldoc -u -f atan2这道命令并记下它的输出结果。
结果如下
=over 8
=item atan2 Y,X
X<atan2> X<arctangent> X<tan> X<tangent>
Returns the arctangent of Y/X in the range -PI to PI.
For the tangent operation, you may use the C<Math::Trig::tan>
function, or use the familiar relation:
sub tan { sin($_[0]) / cos($_[0]) }
Note that atan2(0, 0) is not well-defined.
=back
perldoc是用于阅读Perl以及相关扩展和工具程序的说明文档。以上的命令在执行时,显示的是三角函数atan2的信息。
3 键入第二支范例程序,看看它会输出什么。你能看出来,它是如何改变perldoc命令的输出结果的吗?
#!/usr/bin/perl
@lines = `perldoc -u -f atan2`;
foreach (@lines)
{
s/\w<([^>]+)>/\U$1/g;
print;
}
输出结果
=over 8
=item atan2 Y,X
ATAN2 ARCTANGENT TAN TANGENT
Returns the arctangent of Y/X in the range -PI to PI.
For the tangent operation, you may use the MATH::TRIG::TAN
function, or use the familiar relation:
sub tan { sin($_[0]) / cos($_[0]) }
Note that atan2(0, 0) is not well-defined.
=back
和练习2的结果对比后,发现
×2中的<>在3中没有了,并且<>中的字母在3中全部该为大写
×<>前面的一个字母在3中被删除了
复习笔记
×Larry给Perl的定位:Perl填补低级语言(如C、C++或者汇编语言)和高级语言(如shell程序设计)之间的空隙。
×Perl很容易使用,但学习Perl并不会特别容易。
×Perl很适合用来在3分钟内写出急救的程序。
×Perl程序提供给他人时,提供的是源代码,而不是二进制的可执行文件。