print a cat y n match print a cat

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: perl 的号 There's More Than One Way To Do It ) print sprintf "%b", hex $hex; 8 Spring, 2010 Spring, 2010 Functions working with HASH, 1 • Nevery call print %hash; since hash is orderless. • @key = sort keys %hash – foreach $key (sort keys %hash) {print $hash{$key};} • @key = keys %hash; @value = values %hash; • ($key, $val) = each(%hash) # less memory use each( ) returns once a pair, returns undef at last. 历遍哈希表 print "$key=$value\n" 环境变量在hash表%ENV中 while (($key,$value) = each %ENV); # never modify %hash inside the while each loop!!! TZ=BJT-8 PROCESSOR_REVISION=0806 NUMBER_OF_PROCESSORS=1 USERPROFILE=C:\WINNT\Profiles\xfzhou TMPDIR=c:/temp COMPUTERNAME=N30 ... Q: how to access environment variables in C programs? 正则表达式 • 计算理论中的正则表达式 • UNIX中的正则表达式 • Perl的文本匹配和替换 9 13 Spring, 2010 Spring, 2010 Functions working with HASH, 2 • Remove one hash from hash table – 删除单个元素: delete $hash{$key};# remove whole pair – This is wrong: undef $hash {key}; #key still exists – 删除hash片断: delete @hash{key1, key2, key3…}; Try some Regular Expressions $a = 'dog catches cats.'; print $a =~ /cat/ ? 'Y ' : 'N '; # Match print $a =~ /^cat/ ? 'Y ' : 'N '; $a =~ s/cat|dog/pet/g; # Substitute print "\n$a\n"; $a =~ tr/a-z/za-y/; # Tra...
View Full Document

This note was uploaded on 04/04/2010 for the course EE INFO130098 taught by Professor Zhou during the Spring '10 term at Fudan University.

Ask a homework question - tutors are online