内容:
1.q,qq,qw,qx
2.$_
3.打开文件2种方式
4.defined,undef
执行(1)
[root@zbk11g ~]# perl -e'
> print q/this is a biken/;
> '
this is a biken[root@zbk11g ~]#
[root@zbk11g ~]# perl -e'
> print qq/this is a biken/;
> '
this is a bike
[root@zbk11g ~]# perl -e'
> print qw/this is a biken/;
> '
thisisabiken[root@zbk11g ~]#
[root@zbk11g ~]# perl -e'
> print qx/this is a biken/;
> '
[root@zbk11g ~]# perl -e'
> print qx/date/;
> '
Wed Apr 10 19:16:19 PDT 2013
[root@zbk11g ~]#
小结:q=单引,qq=双引,qw={'$name1','$name2'},qx=反引··,并且qw在输出时只输出变量不包含空格;
(2)
$_为默认输入变量
[root@zbk11g ~]# perl p9
china is my motherland
do|you|know
[root@zbk11g ~]# more p9
#!/usr/bin/perl
open("FL2","txt") or die "can't open the file!";
while(<FL2>)
{
print $_; #文本的第一行,第二行循环输出;
}
close FL2;
[root@zbk11g ~]# more txt
china is my motherland
do|you|know
(3)
1.
[root@zbk11g ~]# more p9
#!/usr/bin/perl
open("FL2","txt") or die "can't open the file!";
while(<FL2>)
{
print $_;
}
close FL2;
2.
[root@zbk11g ~]# more p9
#!/usr/bin/perl
#open("FL2","txt") or die "can't open the file!";
open "FL2","<","txt" or die "can't open the file!";
while(<FL2>)
{
print $_;
}
close FL2;
(4)
[root@zbk11g ~]# perl p9 OK [root@zbk11g ~]# more p9 #!/usr/bin/perl $na="name"; print "OKn" if defined $na; [root@zbk11g ~]# perl p9 [root@zbk11g ~]# more p9 #!/usr/bin/perl $na="name"; undef $na; print "OKn" if defined $na; 小结:defined判断后面的变量是否有效,有效有1,无效为0;undef将原定义的变量失效;