Perl(二)——不常见技巧

前言:

刚开始学Perl,记录一些我认为不常见(未必)的技巧。

chomp

#用于删除字符串结尾的换行符。
####################
#!/usr/bin/perl
use strict;
use warnings;
my $path = `pwd`;    # `pwd`使shell输出当前文件夹地址,输出包含一个换行符

my $another_path = $path;    # 复制一个同名字符串
print("$path");

chomp($path);   # 删除字符串结尾换行符
die ("error") unless(-d $path);
print "nothing wrong";
my $another_path = $path
die ("error happend") unless(-d $another_path); #由于存在换行符,会输出error msg

qw

# qw函数用于给每个字符串加上引号
@word = qw(this is password);
原文地址:https://www.cnblogs.com/lizhiqing/p/13225941.html