perl语言hello world程序

先验证linux是否安装了perl,使用perl -v测试

[root@localhost shell]# perl -v

This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 33 registered patches, see perl -V for more detail)

Copyright 1987-2012, Larry Wall

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环境,如果没有安装,网上搜索相关教程安装。

运行perl程序

可以使用交互式方式,使用-e选项来执行代码,如下

[root@localhost ~]# perl -e 'print "hello world \n"'
hello world 

我们也可以变现perl脚本文件,然后赋予执行权限,进行执行,如下所示:

[root@localhost shell]# cat hello.pl 
#!/usr/bin/perl
print "hello huangbaokang\n";

赋予执行权限

[root@localhost shell]# chmod u+x hello.pl

执行如下:

[root@localhost shell]# ./hello.pl 
hello huangbaokang

以上print语法也可以使用括号来输出字符串

print("hello huangbaokang\n");

perl里的注释跟shell编程类似,用#号注释单行
多行注释用=pod开始 =cut结尾,这个我还是第一次见,跟其他编程语言不一样。

#!/usr/bin/perl
 
# 这是一个单行注释
print "Hello, world\n";
 
=pod 注释
这是一个多行注释
这是一个多行注释
这是一个多行注释
这是一个多行注释
=cut
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄宝康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值