数据结构:
原文:
Perl has three data structures: scalars, arrays of scalars, and associative arrays of scalars, known as ``hashes''. Normal arrays are indexed by number, starting with 0. (Negative subscripts count from the end.) Hash arrays are indexed by string.
Copy翻译:
Perl 有三种数据结构: 数值, 数值的数组, 还有数值的关联数组, 即``哈希表''. 普通的数组以数字为索引, 从 0 开始(负值的下标从数组尾部开始计算). 哈希表中的元素是以字符串索引.
e.g.:
数值变量以 '$' 打头, 当引用数组中的一个元素时也一样. 意思是"这". 举例:
$days # 数值变量 "days" $days[28] # 数组 @days 的第29个元素 $days{'Feb'} # 哈希表 %days 中 'Feb' 代表的数值 $#days # 数组 @days 的最大下标
当表示整个数组或数组的一部分时, 用 '@' 打头, 意思是 "这些" 或 "那些"
@days # ($days[0], $days[1],... $days[n]) @days[3,4,5] # 即 @days[3..5] @days{'a','c'} # 即 ($days{'a'},$days{'c'})
当表示整个哈希表时用 '%' 打头:
%days # (key1, val1, key2, val2 ...)
语法入门:
注释:#
在.bat 文件中的使用:
以
#!perl 代表Perl脚本开始,以 __END__ 代表结束。
实例:
来看一下一个perl脚本最上面的几句,和C#的using同样的功能,是把Perl的一些模块引入近来,可以在%Perl Install Dir%/lib/中找到,扩展名为.pm.
For example:
use strict; #
use File::Find;
use File::Basename;
Some always used functions(or methods)
unlink : seems use it to delete a file
-e : to judge if file exists