基本数据类型:
标量、数组、哈希、函数
$、@、%、&
标量,指示符:$
my $aim;
$aim = 1000000000; # 整型
my $act = 1.5; # 浮点数
$act = 1.5e+10; # 浮点数
my $gain = “4,5000w”; # 字符串
$gain = ‘Novo gene’; # 字符串
my $reality = undef; # 相当于my $reality;
单引号与双引号:
my $pay = 6000;
print “The pay is $pay\n”;
# 显示:The pay is 6000
print ‘The pay is $pay\n’;
#显示: The pay is $pay\n
print “The pay is \$$pay\n”; #使用“\”
#显示:The pay is $6000
“\n”换行;“\t”制表符;
数组,指示符:@
my @array = (1,2,3,4);
@array= (1 .. 4);
print “@array\n”; #显示:1 2 3 4
打印数组array的第1个元素:
print “$array[0]\n”; # 显示:1,数组索引号从0开始
把数组的最后一个元素赋值为10:
$array[-1] = 10; # @array:(1,2,3,10)
my @array2 = (“a”, ”b”, ”c”, 1, 2);
@array2= qw(a b c 1 2);
哈希(散列、关联数组),指示符:%
特征:键(key)=>值(value);键和值一一对应
my %hash;
%hash = (a=>1, b=>2, c=>3);
print $hash{a}; # 显示:1
print “b => $hash{b}\n”; # 显示:b => 2
%hash = (‘a’, 1, ‘b’, 2, ‘c’, 3);
$hash{d} = 1