保护hash数据结构的包:
use Hash::Util qw(lock_keys lock_value lock_hash);
# Do not allow any new keys to be added to our hash. #Existing keys will remain, and their values can still be modified.
# The hash keys must be locked before locking values.lock_keys(%employee);
# We do not allow employees to change their name.
lock_value(%employee,"name");
# Lock all the keys and the values in our hash, making it
# completely read-only. No keys or values can be changed,
# added or deleted.
lock_hash(%constants);
==============================
my $year=substr($d,0,4);
my $month=substr($d,4,2);
my $mday=substr($d,6,2);
my $d_info = strftime("%w %d", 0, 0, 0, $mday , $month - 1, $year - 1900, -1, -1, -1);
这时如果month是以0开头的比如09,通过$month-1后,strftime可以按照期望的work。
但是如果直接写 09 - 1 时,就不work了。
因为09被当成8进制,不被strftime接受了。
这个又一次体现了在perl中context的特性。
===============================
一些one-line command
perl -naF 'next if /^#/; print "$F[3]\n"'
perl -e 'for("MachineB","MachineC","MachineD"){`scp command.pl $_:`; `ssh $_ command.pl`; }'.
ls | perl -e '@a=<>;print $a[rand(@a)]'
perl -pi.bak -e 's/Bill Gates/Microsoft CEO/g; s/CEO/Overlord/g'
perl -n -e 'chomp;print $_,$.%5?":":"\n"' ufile
===============================
perldoc -q/-f str
#帮助查询
===============================
$num = ord($char);
$char = chr($num);
#数字比字符快,有心情可以用用数字代替字符
阅读(1453) | 评论(0) | 转发(0) |