001.hello perl

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013803572/article/details/46984355

perl的安装就不多讲了,linux下一般都自代有perl环境,无须安装。在windows下,去官网下载安装包安装即可,安装完成后配置一下环境变量,否则无法在命令行使用perl命令。安装完成后可使用以下命令测试。

Microsoft Windows [版本 10.0.10162]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\Potter>perl -v

This is perl 5, version 20, subversion 2 (v5.20.2) built for MSWin32-x64-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2015, Larry Wall

Binary build 2001 [298913] provided by ActiveState http://www.ActiveState.com
Built Mar 24 2015 12:09:44

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.

perl的第一个程序,在命令行打印Hello World!
新建一个文本文件hello.pl,后缀可要可不要。
键入以下代码:

print "Hello World!\n";

进入到据文件夹:

D:\perl_test>perl hello.pl
Hello World!

第一个perl程序已经完成。

改用say命令打印Hello World!,它的效果与print基本相同,但say可以自动换行。

#!H:\Perl64\bin\perl

use 5.010;

say "Hello World!";

这个是Perl5.10的新特性,所以使用use 5.010告诉perl,我们要引入该版本中的新特性。也可以理解为这个程序只能在perl5.10版本及其以后的版本中运行。

《Perl语言入门第六版》24页

第一行其实是一个有特殊意义的注释,在Unix系统中如果一个文件以#!开头,那么后面跟着的就是来执行这个文件的程序路径

《Perl语言入门第六版》25页

猜你喜欢

转载自blog.csdn.net/u013803572/article/details/46984355