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

Perl 开发的学习-2_职场

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

#!/usr/bin/perl

$str="short";

$string="long";

print "match longest $string\n";

print "match shortlets ${str}ing\n";

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

match longest long

match shortlets shorting

[root@windriver-machine test]#

Perl 开发的学习-2_职场_02Perl 开发的学习-2_休闲_03Perl 开发的学习-2_特殊符号说明_04

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

#!/usr/bin/perl

print "bell ring:\a\n";

print "back#\bspace\n";

print "copy\rabc\n";

print "abc\tdef\n";

print "the\$var\n";

print "a quote \" in string \n";

print "a quote \\ in string \n";

print "\045\n";

print "\x25\n";

print 'the \$var\n';

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 \$var\nthis is the first line,

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

Perl 开发的学习-2_休闲_05

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

#!/usr/bin/perl

$var=1;

print q(the $var\n);

print qq(is $var\n);

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

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

the $var\nis 1

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

Perl 开发的学习-2_perl _06

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

2

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

#!/usr/bin/perl

$r=$und+2;

print "$r\n";

[root@windriver-machine test]#

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

#!/usr/bin/perl -w

$r=$und+2;

print "$r\n";

[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]#

Perl 开发的学习-2_特殊符号说明_07

Perl 开发的学习-2_perl _08

Perl 开发的学习-2_perl _09

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

#!/usr/bin/perl

$a="abcd";

chop($a);

print "chop $a\n";

$a="abcd";

chomp($a);

print "chomp $a\n";

$a="abc\n";

chop($a);

print "chop $a|";

$a="abc\n";

chomp($a);

print "chomp $a|";

$a="abc\n\n\n";

$/="";

chomp($a);

print "chomp many $a\n";

$/="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 开发的学习-2_特殊符号说明_10

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

Perl 开发的学习-2_休闲_11

Perl 开发的学习-2_特殊符号说明_12

Perl 开发的学习-2_休闲_13

Perl 开发的学习-2_特殊符号说明_14

Perl 开发的学习-2_特殊符号说明_15

Perl 开发的学习-2_perl _16

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

Perl 开发的学习-2_特殊符号说明_17

Perl 开发的学习-2_休闲_18

Perl 开发的学习-2_特殊符号说明_19 Perl 开发的学习-2_职场_20

Perl 开发的学习-2_特殊符号说明_21

Perl 开发的学习-2_perl _22

Perl 开发的学习-2_特殊符号说明_23

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

#!/usr/bin/perl

print " minus the number before pot:";

$a=25.7%7.6;

print "$a\n";

print "log number is pot:";

$b=(25)**1.5;

print "$b\n";

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

$a='Z';

$a++;

print "$a\n";

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

$a=1;

$b=1;

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

print "$c\n";

$a=1;

$b=1;

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

print "$c\n";

print "=associativity :";

$a=2,$b=1;

$a*=$b+=5;

print "$a\n";

$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]#

Perl 开发的学习-2_特殊符号说明_24