Perl模块之Tie::File
原文:http://hi.baidu.com/mylongwalk/blog/item/004df0220cc2cc4dad34dea0.html
perl的Tie::File模块真是与乎寻常的强大
2 ."e p"????????????
??? 2. autochomp
??? 指定读出记录时是否去除记录分隔符,(默认)为真值时会自动去除分隔符。如:
???? Normally, array elements have the record separator removed, so that if the file contains the text
GoldFrankincenseMyrrh
??? the tied array will appear to contain ("Gold", "Frankincense", "Myrrh")(不包括换行)
If you set?? autochomp
to a false value, the record separator will not be removed. If the file above was tied with
tie (@gifts, "Tie::File", $gifts, autochomp => 0);
?? then the array @gifts
would appear to contain ("Gold\n", "Frankincense\n", "Myrrh\n")
, or (on Win32 systems) ("Gold\r\n", "Frankincense\r\n", "Myrrh\r\n")
.??????
?? 3. splice
???? spice是perl命令,不是此模块所独有,用法如下:
??? splice ARRAY,OFFSET,LENGTH,LIST
??? splice ARRAY,OFFSET,LENGTH
??? splice ARRAY,OFFSET
????splice ARRAY????
??? 从第offset个元素开始,删除长度为length个元素,若list存在,则 用list代替删除掉的数据(若lenght=0,则变成了添加)。若省略length,则删除从offset开始的所有数据。offset和 length都省略则删除所有元素。
除此之外还有mode、memory、dw_size等选项。另外在指定选项时可以在选项前加一个“-”号,即tie(...,-recsep=& gt;...)和tie(...,recsep=>...)这两种形式是等价的。对该模块的进一步说明请参考perldoc Tie::File
http://perldoc.perl.org/Tie/File.html