G match for usr path usr 11 15 perl perl

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: nslate print "$a\n"; Results: YN pet petches pets. ods odsbgdr odsr. 10 14 • Delete a whole hash table – %hash = (); – undef %hash; • Check existence of a hash – if (exists $hash{$key}) {….} – This is wrong: if ($hash{$key}) {….} 值可能是0或undef – This is also wrong: if ( defined $hash{$key}) … • delete和exists函数也可以用于普通数组 很少用 – 和splice( )不同,delete( )后,下标不变,exists( )为假 – 只有delete了数组的最后一个元素,数组才会缩小。 Spring, 2010 Reference to hash table • Reference: \ $Rhash = \%hash; RE Rule 1:通配符,元字符 Spring, 2010 Dereference: % %{$Rhash} is a hash • Refer to anonymous hash $Rh = { 'dog'=>'bark', 'cat'=>'mew', }; print "Sound of dog is ${$Rh}{dog} \n"; • Short hands 省略{}、写成->的样子 – ${$a} ≡ $$a, @{$a} ≡ @$a, %{$a} ≡ %$a, etc – Ref to list: $a = [1, 2, 3, "AAB"] ${$a}[0]=50; $$a[0]=50; $a->[0]=50; # same – Ref to hash:$h= {cat=>"rat", dog=>"meat"} ${$h}{rat}="rice"; $$h{rat}="meat"; print $h->{rat}; – 注意优先级,perl的 $$a[j]和C语言的*x[j]不同 $$a[j]和${$a[j]} 不同 • Literal: m/a/, m/\$/, m/AbCd/ • ^ caret: Begin of a str/line: m/^#/ -- a line begin with pond sign • $ dollar: End of a str/line: s/$/##/m...
View Full Document

Ask a homework question - tutors are online