加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl 开发的学习-2

发布时间:2020-12-16 00:36:14 所属栏目:大数据 来源:网络整理
导读:字符串变量,需要注意单引号与双引号的不同,这一点在Shell里也一样,就是单引号不进行转义 [root@windriver-machine test]# cat str.pl #!/usr/bin/perl $str="short"; $string="long"; print "match longest $stringn"; print "match shortlets ${str}ing

字符串变量,需要注意单引号与双引号的不同,这一点在Shell里也一样,就是单引号不进行转义

[root@windriver-machine test]# cat str.pl

#!/usr/bin/perl

$str="short";

$string="long";

print "match longest $stringn";

print "match shortlets ${str}ingn";

[root@windriver-machine test]# perl str.pl

match longest long

match shortlets shorting

[root@windriver-machine test]#

root@windriver-machine test]# cat esc.pl

#!/usr/bin/perl

print "bell ring:an";

print "back#bspacen";

print "copyrabcn";

print "abctdefn";

print "the$varn";

print "a quote " in string n";

print "a quote in string n";

print "45n";

print "x25n";

print 'the $varn';

print 'this is the first line,

this is second line.n';

[root@windriver-machine test]# perl esc.pl

bell ring:

backspace

abcy

abc def

the$var

a quote " in string

a quote in string

%

%

the $varnthis is the first line,

this is second line.n[root@windriver-machine test]#

[root@windriver-machine test]# cat qq.pl

#!/usr/bin/perl

$var=1;

print q(the $varn);

print qq(is $varn);

print qq<string "str"(var) in qq>;

[root@windriver-machine test]# perl qq.pl

the $varnis 1

string "str"(var) in qq[root@windriver-machine test]#

[root@windriver-machine test]# perl undef.pl

2

[root@windriver-machine test]# cat undef.pl

#!/usr/bin/perl

$r=$und+2;

print "$rn";

[root@windriver-machine test]#

[root@windriver-machine test]# cat undef.pl

#!/usr/bin/perl -w

$r=$und+2;

print "$rn";

[root@windriver-machine test]# perl undef.pl

Name "main::und" used only once: possible typo at undef.pl line 2.

Use of uninitialized value in addition (+) at undef.pl line 2.

2

[root@windriver-machine test]#

root@windriver-machine test]# cat chp.pl

#!/usr/bin/perl

$a="abcd";

chop($a);

print "chop $an";

$a="abcd";

chomp($a);

print "chomp $an";

$a="abcn";

chop($a);

print "chop $a|";

$a="abcn";

chomp($a);

print "chomp $a|";

$a="abcnnn";

$/="";

chomp($a);

print "chomp many $an";

$/="cd";

$a="abcd";

chop($a);

print "chop $a|";

$a="abcd";

chomp($a);

print "chomp $a|";

[root@windriver-machine test]# perl chp.pl

chop abc

chomp abcd

chop abc|chomp abc|chomp many abc

chop abc|chomp ab|[root@windriver-machine test]#

注意这些函数是直接修改原变量,不是返回值。

操作符与操作数是计算机里的基本的概念,同样在Perl 中也一样。

移位运算首先操作符一定是整数,否则是无法进行移位操作的。

[root@windriver-machine test]# cat op.pl

#!/usr/bin/perl

print " minus the number before pot:";

$a=25.7%7.6;

print "$an";

print "log number is pot:";

$b=(25)**1.5;

print "$bn";

print "auto increment for string,donot extrand length:";

$a='Z';

$a++;

print "$an";

print "the prority of || and or is not same:n";

$a=1;

$b=1;

$c=($a+=0||$b);

print "$cn";

$a=1;

$b=1;

$c=($a+=0 or $b);

print "$cn";

print "=associativity :";

$a=2,$b=1;

$a*=$b+=5;

print "$an";

$a=2,$b=1;

($a*=$b)+=5;

print $a;

[root@windriver-machine test]# perl op.pl

minus the number before pot:4

log number is pot:125

auto increment for string,donot extrand length:AA

the prority of || and or is not same:

2

1

=associativity :12

7[root@windriver-machine test]#

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读