ebook65-1

Similar documents
ebook65-5

ebook15-C

epub 61-2

ebook8-30

epub 75-1

Microsoft Word - linux命令及建议.doc

epub 63-3

ebook65-20

4.进度控制(网络计划)0.ppt

ebook 99-9

Microsoft Word - PS2_linux_guide_cn.doc

ebook43-11

ebook35-2

ebook37-11

C/C++程序设计 - 字符串与格式化输入/输出

ebook140-3

PowerPoint 演示文稿

ebook

IP505SM_manual_cn.doc

像 客 样 使 命令行 徐 东

ebook140-9

ebook

R F I D R F I D C E P S R F I D 96 R F I D Metalib & SFX M U S E Sm a rt we a ve r

Persuasive Techniques (motorcycle helmet)

Learn_Perl 3-02.pdf

AL-M200 Series

软件测试(TA07)第一学期考试

Progperl.PDF

ebook70-5

epub 73-5

ebook4-12

ebook37-4

<4D F736F F D20365F B0E6D2FDD6A4B1A8B8E6B2E5D2B3>

, 7, Windows,,,, : ,,,, ;,, ( CIP) /,,. : ;, ( 21 ) ISBN : -. TP CIP ( 2005) 1

WWW PHP


因 味 V 取 性 又 鸟 U 且 最 大 罗 海 惜 梅 理 春 并 贵 K a t h l ee n S c h w e r d t n er M f l e z S e b a s t i a n C A Fe rs e T 民 伊 ' 国 漳 尤 地 视 峰 州 至 周 期 甚 主 第 应

C/C++ - 文件IO

2004版中文核心期刊要目总览

Windows XP

ebook140-8

Perl

Microsoft Word

ebook 178-3

/ / (FC 3)...

WinMDI 28

逢 甲 大 學

ebook15-4

C/C++ - 字符输入输出和字符确认

Lorem ipsum dolor sit amet, consectetuer adipiscing elit

本文由筱驀釹贡献

Microsoft Word doc

(Microsoft Word - 5\276\302\270g\260\252\256v .doc)

I 宋 出 认 V 司 秋 通 始 司 福 用 今 给 研 除 用 墓 本 发 共 柜 又 阙 杂 既 * *" * " 利 牙 激 I * 为 无 温 乃 炉 M S H I c c *c 传 统 国 古 代 建 筑 的 砺 灰 及 其 基 本 性 质 a 开 始 用 牡 壳 煅 烧 石 灰 南

Unix®t Œ fi z.PDF

基 督 教 培 英 中 心 園 地 培 英 中 心 動 向 地 址 :# Cambie Road, Richmond, B.C. 電 話 : 傳 真 : 電 郵 網 址 :

c pdf

蔡 氏 族 譜 序 2

ebook62-1

该 奈 自 受 PZ 多 透 soc i e B t h y. y t is NA YL OR exp os ed t h a t b e i n g wh o res or sa in t es s e s we r e m ad e n b ot om. M ean wh i l e NA YL

ebook70-19

LOVE IS OVER LOVE LOVE LOVE LOVE IS EVERYTHING LOVE LOVE LOVE LOVER'S QUEEN LYDIA MAYBE TOMORROW MEN'S TALK MY DEAR MY FRIEND MY OH MY MY SUMMER DREAM

ebook204-2

中文核心期刊要目总览-(2004年版) 简明目录

epub83-1

Untitiled

ebook177-1

<D0A1B0E02E707562>

ebook14-4

ebook45-5

RSBook_CN.indb

ebook2-24

untitled

Transcription:

Perl 1Perl 2Perl 3 4 5 6 7 8

1P e r l P e r l We b P e r l P e r l P e r l P e r l We b P e r l P e r P e r l H T M L We b P e r l P e r l P e r l P e r l P e r l p e r l p e r l P e r P E R L P e r l Practical Extraction and Report Language P E R L P e r l P e r l P e r Pathologically Eclectic Rubbish Lister P e r l P e r l P e r l 1.1 Perl P e r l P e r l P e r l P e r l

4 Perl 1.1.1 Perl P e r l P e r U N I X P e r l Windows NT P e r l Windows NT (Resource Kit) P e r l U N I X $ % b a s h % s h e l l P e r l P e r l $ $ perl -v command not found P e r l P e r l 5 5. 004 5. 005 5. 6 P e r l 4. x Perl 4 Perl 4 5. 005 P e r l 5. 6 1 999 Wi n d o w s P e r l 1-1 M S - D O S 1-1 D O S P e r l

1Perl 5 C:\> perl -v P e r l 5 D O S Bad command or file name P e r l M a c i n t o s h 1-2 File Find C o m m a m d - f F i n d M a c P e r l P e r l A p p l e About MacPerl Version 5.2.0 Patchlevel 5.004 M a c P e r l 1-2 M a c i n t o s h P e r l 1.1.2 Windows 95/98/NT Perl Wi n d o w s P e r l C M a k e f i l e s h e l l P e r P e r 16 P e r l Wi n d o w s P e r l P e r l ActiveState To o l P e r l Wi n d o w s 1-3 P e r l ActiveState Community License A c t i v e S t a t e U R L h t t p :// w w w. A c t i v e S t a t e. c o m P e r l P e r l A c t i v e S t a t e A c t i v e S t a t e P e r l 1-3 A c t i v e S t a t e Wi n d o w s P e r l A c t i v e S t a t e P e r l P e r l A c t i v e S t a t e We b P e r l

6 Perl 1.1.3 UNIX Perl U N I X P e r l P e r h t t p :// w w w. p e r l. c o m D o w n l o a d s S t a b l e P r o d u c t i o n ANSI C P e r l U N I X P e r l L i n u x S o l a r i s A I X U N I X P e r l P e r l S t a b l e. t a r. g z $ gunzip stable.tar.gz $ tar xf stable.ta r g u n z i p h t t p :// w w w. g n u. o rg g z i p $ sh Configure C o n f i g u r e E n t e r P e r l U N I X $ m a k e P e r l $ make test # make install make test P e r l make install # P e r l make install P e r l $ perl -v U N I X P e r l h t t p :// w w w.perl.com P e r l

1Perl 7 1.1.4 Macintosh Perl Macintosh Perl M a c P e r l C PA N h t t p : / / w w w. p e r l. c o m / C PA N / p o r t s / m a c MacPerl appl.bin S t u ffit Expander M a c P e r l P e r l S h u c k M a c P e r l MacOS 8 I n t e r n e t A d v a n c e d - >File Mapping S h u c k. p o d M a c P e r l. p h. p l. p l x. p m. c g i. x s P e r l T E X T MacOS 7 I n t e r n e t C o n f i g I n t e r n e t C o n f i g H e l p e r s p o d s h u c k M a c P e r l M a c P e r l h t t p :// w w w. p e r l. c o m / C PA N / p o r t s / m a c 1.2 P e r l P e r l P e r l Perl 5.005 1700 FA Q P e r l Wi n d o w s U N I X Pe r l p e r l d o c p e r l d o c p e r l d o c U N I X D O S

8 Perl p e r l f u n c P e r l p e r l o p P e r l p e r l f a q Perl FA Q p e r l f u n c perldoc perlfunc perldoc perl - t f p e r l d o c P e r l p r i n t $ perldoc -tf print FA Q P e r l P e r l FA Q FA - q FA Q P e r l $ perldoc -q support FA Q Who Supports Perl? Who develops it? Why is it free? P e r l P e r l 1.2.1 U N I X P e r l m a n y e s P e r l m a n P e r l p e r l d o c U N I X m a n $ man perl Microsoft Wi n d o w s A c t i v e S t a t e P e r l H T M L We b We C :\ P e r l \ h t m l M a c i n t o s h M a c P e r l S h u c k M a c P e r l P e r l 1-4 1-4 M a c P e r l S h u c k

1Perl 9 1.2.2 p e r l d o c s h e l l p e r l d o c s h e l l PAT H P e r l P e r l P e r l P e r l P e r l P e r We b P e r l h t t p :// w w w. p e r l. c o m P e r l P e r l 1.3 Perl P e r l Microsoft Windows N o t e p a d DOS E D I T. E X E U N I X v i e m a c s p i c o M a c M a c P e r l F i l e N e w P e r l M i c r o s o f t Wo r d Wo r d p a d Wo r d P e r f e c t P e r l 1.3.1 P e r l # h e l l o P e r l Wi n d o w s M a c i n t o s h. p l. p l x h e l l o. p l 1.3.2 U N I X Microsoft Wi n d o w s M S - D O S

10 Perl s h e l l c d h e l l o D O S U N I X C:\PROGRAMS> perl hello P e r l Hello, world! Bad command or file name perl : command not found p e r l p e r l s h e l l PAT H C a n t open perl script hello : A file or directory does not exist P e r l h e l l o h e l l o syntax error P e r l h e l l o U N I X c a t D O S t y p e M a c P e r l S c r i p t R u n h e l l o p e r l M a c P e r l F i l e O p e n M a c P e r l R u n 1.3.3 perl hello p e r l p e r l perl P e r l h e l l o ) P e r l perl perl h e l l o 1.3.4 Perl H e l l o

1Perl 11 #! / u s r / b i n / p e rl P e r l # P e r l # / u s r / b i n / p e r l perl U N I X # U N I X P e r l We b A p a c h e # p e r l # print "Hello,World!\n"; P e r l P e r l p r i n t p r i n t p r i n t P e r l P e r l p r i n t H e l l o, Wo r l d! \ n P e r l \ n P e r l 1.3.5 P e r l P e r P e r l pr int 25 61 Hello Wo r l d! P e r l P e r l P e r Pe r l P e r l p e r l s t y l e

12 Perl P e r l P e r Pe r l Perl Journal h t t p :// w w w. tpj. c o m Pe r l Obfuscated Perl Contest 1.4 P e r l P e r l P e r l P e r l P e r 1.5 1.5.1 P e r l P e r P e r l P e r l Larry Wa l l P e r l P e r U N I X P e r l # p e r l / u s r / b i n / p e r l / u s r / l o c a l / b i n / p e r c h m o d h e l l o U N I X s h e l l chmod 755 hello h e l l o. / h e l l o P e r l U N I X t e s tu N I X s h e l l t e s t t e s s h e l l # P e r l perl programname 1.5.2 1) Perl p e r a.

1Perl 13 b. c. D O S 2) P e r l a. http://www. m i c r o s o f t. c o m b. http://www. p e r l. c o m c. http://www. p e r l. n e t 3) P e r l a. perlsyn b. perlop c. perlfaq 1.5.3 1) b P e r l DOS shell c 2) b 3) a perldoc perl 1.5.4 FA Q ( ) FA Q h t t p :// w w w. p e r l. c o m

2P e r l P e r l P e r l P e r l P e r l π 15 P e r l P e r l P e r l P e r l P e r 2.1 P e r l 2.1.1 P e r l 2-1 P e r l 2-1 6 1 2. 5 1 5. 0 0. 7 3 2 0 5 0 8 1 e 1 0 6. 67 E - 33 e E 4 _ 2 9 4 _ 2 9 6

2Perl 15 e P e r l 0 010 P e r l 8 P e r l 16 2 p e r l d a t a 2.1.2 P e r l A S C I I 1 A S C I I P e r l ' ' " " \ P e r l P e r l Go Go ahead,make my d a y P e r l P e r l P e r l P e r l 2-2 P e r l

16 Perl 2-2 \ n \ r \ t \ b \ u \ l \\ \' ' ' ' \" " P e r l p e r l d o c Pe r l p e r l o p Quote and Quote-like Operators P e r l q q q q q q q q q q q q q q q < >,{},[] q q q P e r l 2.2 P e r l P e r l

2Perl 17 P e r l P e r l a z, A Z _ $ v a l u e $ V A L U E $ V a l u e $ v a l u E P e r l $ _ $$ / $ 2 $ $ P e r l P e r l P e r l P e r l P e r l 0 Perl - w #! - w P e r l P e r l P e r l Use of uninitialized value $_ P e r l $ $ $ _ $ _ $ _ 6 $ _

18 Perl 2.3 P e r l P e r l P e r 3 2-1 P e r l 2-1 P e r l 1 P e r l - w P e r l 3 50 $ r a d i u s 5 $ r a d i u s * * * 2 $ a r e a 6 $ a r e a 2 54 * $ rj a v as i n $ p i * 8 $ t = 6 P e r l 2.3.1 2-1 = $ a $ b $ c 42 $ c 42 $ b $ c = 42 42 $ a $b = 42 $ a $ c o u n t P e r l

2Perl 19 2.3.2 P e r l 2-3 2-3 5 + $t 5 $ t $y - $x $ y $ x $e * $pi $ e $ p i $f / 6 $ f 6 24 % 5 24 5 4 4 * * 2 4 2.3.3 P e r l. $ a $ b $ a $ H e l l o, World! Nice to meet you $ c $ a $ b P e r l P e r l P e r l $ n a m e J o h n p r i n t I used the variable $name $ n a m e

20 Perl P e r l P e r l P e r l $ d a t e $ d a t e d a y x x - x 70 $ l i n e 2.4 P e r l P e r l 2.4.1 6 / 3 6 3 5 * 2 5 2 - P e r l - 2-4 P e r l P e r l 2-4 2-4 i n t i n t 5. 6234 5 l e n g t h l e n g t h (" n o s e ") 4 l c u c l c ME TO O u c hal 9000 me too l c HAL 9000 c o s c o s 5 0 50. 964966 r a n d r a n d 5 0 0 1

2Perl 21 1 P e r l p e r l d o c P e r l p e r l o p p e r l f u n c 2.4.2 P e r l + + 1 $ c o u n t e r 1 P e r l - - 1 2.4.3 < > 5 5 < S T D I N > P e r l < S T D I N >

22 Perl 9. 5 < S T D I N > E n t e r $ s i z e < S T D I N > E n t e r c h o m p c h o m p 1 0 2.4.4 = P e r l P e r l = = $ a = $ a + 3 $ a + 2.4.5 P e r l P e r l P e r l P e r l

2Perl 23 P e r l 0 P e r l P e r l P e r l P e r # - w - P e r l P e r l A rgument x isn t numeric x 2.5 2-2 I n t e r e s t 1 2-2 1 - w 3 4 $ p m t 5 $ p m t

24 Perl 7 9 $ i n t e r e s t 11 1 3 $ m o n s 1 6 $ i n t e r e s t 12 $ i n t e r e s t 1 8 $ t o t a l 2 0 2 1 perl Interest 2-3 2-3 2.6 P e r l P e r l 2.7 2.7.1 p r i n t f 9 P e r l p r i n t f r o u n d P O S I X P e r l Intel UNIX 300 300 0 14 2.7.2 1) q q a. b.

2Perl 25 2) $ c $ a = 6 ; $ a + + ; $ b = $ a ; $ b --; $ c = $ b ; a. 6 b. 7 c. 8 3). a. b. 2.7.3 1) a q q 2) a $ a 6 $ a 7 $ b $ b 6 $ c 3) b P e r l T I M TO W T D I q q $ a $ b $ c) : 2.7.4 32 5 / 9 75 21. 1 2-3 p r i n t f i n t

3 2 P e r l X P e r l P e r l P e r l 3.1 P e r l

3 27 P e r l P e r l P e r l 3.2 if P e r l i f i f T R U E FA L S E $r == 5 = = $ r 5 p r i n t $ r p r i n t i f i f - e l s e e l s e $ r = $ r = = = = =

28 Perl i f e x p r e s s i o n 1 B L O C K 1 e l s i f e x p r e s s i o n 2 B L O C K 2 e x p r e s s i o n 1 e x p r e s s i o n 2 B L O C K 3 P e r l 3.2.1 = = i f P e r l 3-1 3-1 = = $x == $y $ x $ y > $x > $y $ x $ y < $x < $y $ x $ y >= $x >= $y $ x $ y < = $x <= $y $ x $ y! = $x!= $y $ x $ y 3-1 i f 3-1

3 29 1 P e r l - w 3 rand 10 0 10 i n t 0 9 $ i m _ t h i n k i n g _ o f 4 ~ 6 $ g u e s s 8 ~ 9 $ g u e s s $ i m _ t h i n k i n g _ o f 1 0 ~ 11 $ g u e s s $ i m _ t h i n k i n g _ o f 1 2 ~ 1 3 3-1 $ f i r s t $ l a s t P e r l 0 i f P e r l i f 0 == 0 = = s i m p l e S i m o n P e r l 3-2 3-2 e q $s eq $t $ s $ t g t $s gt $t $ s $ t l t $s lt $t $ s $ t g e $s ge $t $ s $ t l e $s le $t $ s $ t n e $s ne $t $ s $ t A S C I I 1506 H a p p y H a p p y h a p p y 3.2.2 Perl...... P e r l P e r

30 Perl 0 0 u n d e f 3-3 3-3 0 0 10 0 9>8-5 + 5 0 0 0.00 0 0 x 0 0 0 0 b 0 0 e 00 "" "" " 0. 00 " 0 " 00 " 0. 00 "0.00" + 0 0. 00 + 0 i f u n d e f P e r l u n d e f u n d e f 0 i f u n d e f u n d e 0 u n d e f P e r l Use of uninitialized value 3.2.3 $ x $ y $ z i f

3 31 P e r l 3-4 3-4 && a n d $s && $t $ s $ t $q and $p $ q $ p o r $a $b $ a $ b $c or $d $ c $ d! n o t! $m $ m not $m $ m 3-4 1 3 $ a a n d $ b $ a P r i n t 4 $ d $ o r $ b $ b p r i n t 5 $ d $ d 4 o r $ b 1 o r $ c $ c p r i n t P e r l i f $ a $ b o r $ a $ b o r a n d o r $ m e s s a g e

32 Perl o r o o r &&/ a n d / n o t P e r l 5 && 7 3.3 3-1 3.3.1 while w h i l e w h i l e w h i l e P e r l w h i l e 3-2 3-2 while 1 $ c o u n t e r 0 2 $counter < 10 4 $ c o u n t e r 1 5 } 2 { P e r l w h i l e

3 33 3.3.2 for f o r P e r l f o r 3 i n i t i a l i z a t i o n t e s t i n c r e m e n t P e r l f o r f o r $ a 0 $ a < 10 $ a = $ a + 2 $ a 2 $ a 10 f o r f o r f o r 3 f o r 3.4 P e r l w h i l e f o r i f P e r l 3.4.1 i f i f i f

34 Perl P e r l i f i 3.4.2 f o r w h i l e i f P e r l l a s t l a s t l a s t $ i 5 w h i l e w h i l e l a s t 3-3 140 100 2 7 0 4 3 5 l a s t $ i $ 3-3 n e x t 0 9 8 $ i n e x t $i % 2 $ i 2 p r i n t 2 $ i n e x t

3 35 3.4.3 P e r l f o r w h i l e M Y B L O C K % $ @ P e r l P e r l f o r w h i l e l a s t r e d o n e x t 3-4 f o r 140 i f O U T E R 140 3.4.4 Perl e x i t P e r l e x i t P e r l 11 0 e x i t e x i t e x i P e r l P e r l 3.5 1

36 Perl 2 3 4 1 4 2 3-4 P r i m e s 1 Perl Primes 3-4 1 - w 3 $ m a x p r i m e s 4 $ v a l u e 5 $ c o u n t 6 w h i l e 7 $ v a l u e 2 8 $ c o m p o s i t e f o r 9 ~ 10 f o r $ v a l u e $ v a l u e 4 2 2 2 3 3 3 11 ~ 14 $ i $ j $ v a l u e $ v a l u e $ c o m p o s i t e f o r 1 7 ~ 20 f o r $ c o m p o s i t e

3 37 3.6 P e r l i f w h i l e u n t i l f o r P e r l P e r 3.7 3.7.1 C s w i t c h c a s e P e r l s w i t c h P e r l P e r l s w i t c h s w i t c h perldoc perlsyn P e r l s w i t c h s w i t c f o r w h i l e i f P e r l Unmatched right bracket Missing right bracket {) P e r l P e r l v i E m a c s U l t r a E d i t 3.7.2 1) w h i l e a. if (not) {} b. while (! condition ) {} 2) (0 and 5) ( " 0 (" or 0 or " ") and (6 and "H e l l o")) or 1 a. b.

38 Perl 3) $i for($i=0; $i<=10; $i++) { } a. 10 b. 9 c. 11 3.7.3 1) b while (! condition ) {} 2) a a n d o r o r 3) c $ i < = 10 $ i 11 3.7.4 3-1 3-4 2

4 P e r l 50 P e r l 3 2 5 $ ab o b $ a B o b P e r l P e r l @ @ F O O P e r l $ n a m e s @ n a m e s $ n a m e s @ n a m e s @ F O O @ n a m e s 7 4.1 (5, 'apple', $x. 3.14159) 4 5 a p p l e $ x π P e r l q w q qw (apples oranges 45.6$x) 4 $ x $ x

40 Perl q w ('apples', 'oranges','45.6' '$x') $ x q w $ x $ x x P e r l.. ( 1.. 1 0 ) 1 10 1 1 1 1 0 (1..10, 20..30); 21 1 1 0 2 0 3 0 1 1 0 2 0 30 10.. 1 ( a.. z ) 26 ( a a.. z z ) 675 a a a b a c a d z x z y z z P e r l P e r l P e r boy=qw(greg Peter Bobby); @ b o y s 3 G r e g P e t e r B o b b y q w 6 2 c o p y = o r i g i n a ; c l e a n = ( ) ; @ o r i g i n a l @ c o p y @ c o p y @ c l e a n

4 41 @ k i d s @ g i r l s @ b o y s P e r l G r e g P e t e r @ k i d s M i k e C a r o l @ f a m i l y @ b o y s @ g i r l s @ k i d s ( M i k e C a r o l ) @ f a m i l y M i k e C a r o l @ f a m i l y @family=qw(greg peter Bobby Marcia Jan Cindy Mike Carol Alice); ($a, $b, $c)=qw (apples oranges bananas); $ a a p p l e $ s b o r a n g e s $ c b a n a n a s $ a p e a c h e s @ f r u i t $ c $ c u n d e f u n d e f $ t $ u $ v q u a i l $ a $ b $ c $ d $ c g o p h e r $ c u n d e f 4.2 print "@array"; @ a r r a y 0 1

42 Perl $ a r r a y [ i n d e x ] a r r a y i n d e x @ t r e e s $ $ $ t r e e s [ 3 ] $ @ t r e e s P e r l $ t r e e s @ t r e e s [ 0 ] $ t r e e s [ 0 ] P e r l @ t r e e s $ t r e e @ 4.2.1 @ t r e e s @ t r e e s P e r l $ # a r r a y n a m e 8 0 7 $ # t r e e s u n d e f $ s i z e = @ a r r a y ; @ a r r a y $ s i z e P e r l $ a r r a y [- 1 ] @ a r r a y $ a r r a y [- 2 ]

4 43 4.2.2 l e v e l l e v e l l e v e l l e v e l l e v e l P e r l P e r l P e r l $ a $ b $ a 4 $ b 3 @ f o o $ a $ b 0 @ m y d a t a 4 i f 4 i f @ m y d a t a P e r l i f ( v o i d ) 9

44 Perl 4.2.3 P e r l P r i n t p r i n t @ f o o print @foo; s c a l a r print acalar (@foo); @ f o o S c a l a r @ f o o @ f o o @ f o o p r i n t 2 c h o m p c h o m p 2 c h o m p < S T D I N > P e r l $ a $ a P e r l P e r End of File E O F U N I X C t r l + D M S _ D O S Wi n d o w s C t r l + Z 1 100 x *

4 45 $ l a s t _ p e t $ l a s t _ p e t iguana l o c a l t i m e l o c a l t i m e p r i n t s c a l a r ( l o c a l t i m e ) Thu Sep 16 23:00:06 1999 l o c a l t i m e 4-1 4-1 l o c a l t i m e $ s e c 0 ~ 59 $ m i n 0 ~ 59 $ h o u r 0 ~ 23 $ m d a y 1 ~ 28 2 9 3 0 3 1 $ m o n 0 ~ 11 $ y e a r _ o ff 1900 1900 4 $ w d a y 0 ~ 6 $ y d a y 0 ~ 364 3 65 $ i s d s t 1 9 l o c a l t i m e 1900 1999 9 9 2000 1 0 0 1999 2000 P e r l 2000 1 9 2 0 2000 4.3

46 Perl 4.3.1 3 w h i l e f o r f o r q w Rocky Road $ i n d e x 0 1 @ f l a v o r s @ f l a v o r s 5 @ f l a v o r P e r l P e r l f o r e a c h 3 f o r e a c h $ c o n e @ f l a v o r s $ c o n e @ f l a v o r s @ f l a v o r s f o r e a c h f o r e a c h $ c o n e @ f l a v o r s 2 $ f l a v o r ice cream 3 I d like a bowl of chocolate ice cream v a n i l l a s t r a w b e r r y @ f l a v o r s ice cream P e r l f o r e a c h f o r f o r e a c h () f o r () 3 f o r 4.3.2 P e r l

4 47 s p l i t S p l i t @ w o r d s T h e q u i c k b r o w n f o x $ _ $ _ $ _ $ _ S p l i t $ _ $ f i r s t c h a r s p l i t 6 s p l i t P e r l s p l i t P e r l j o i n j o i n 1 2 3 4 5 6 7 8 9 10 $ n u m b e r s s p l i t j o i n

48 Perl $ m e s s a g e s p l i t j o i n 4.3.3 P e r l P e r l s o r t S o r t Bush Carter Clinton Ford Nixon Reagan A S C I I A S C I I 11 100 s o r t $ a $ b $ b $ a - 1 0 1 @ n u m b e r s @ n u m b e r s P e r l < = > - 1 0 c m p 7 P e r l r e v e r s e r e v e r s e r e v e r s e (" P e r l " l r e p r e v e r s e ham and eggs green like not do I

4 49 print join(' ', reverse sort l i n e s ); s o r t I a n d d o e g g s g r e e n h a m l i k e n o t j o i n not like ham green egg do and I 4.4 4-1 H a n g m a n perl Hangman 4-1 H a n g m a n

50 Perl 1 - w 3 @ w o r d s 4 ~ 5 @ g u e s s e s @ w r o n g 7 @ w o r d s $ c h o i c e r a n d @ w o r d s 4 r a n d 0 3 0 4 8 h a n g m a n 1 0 $ c h o i c e m y s t e r y @ l e t t e r s 11 h a n g m a n @ h a n g m a n $ h a n g m a n [ 0 ] $ h a n g m a n [ 1 ] 1 2 @ b l a n k w o r d (0) x scalar @ h a n g m a n @ h a n g m a n @ b l a n k w o r d 0 35 1 3 ~ 14 O U T E R h a n g m a n 1 5 ~ 21 f o r e a c h @ b l a n k w o r d @ b l a n k w o r d 2 3 ~ 25 $ w r o n g 1 24 h a n g m a n 0 1 2 6 ~ 27 c h o m p 2 8 ~ 30 @ g u e s s e s 13 3 2 ~ 38 @ l e t t e r s @ b l a n k w o r d @ b l a n k w o r u n d e f $ r i g h t 1 3 9 $ w r o n g 4 0 ~ 43 @ b l a n k w o r d

4 51 4 5 13 4-2 H a n g m a n 4-2 Hangman s p l i t j o i n f o r e a c h H a n g m a n 4.5 P e r l P e r l P e r l 4.6 4.6.1 7 7 4.6.2 1) $ a $ b a. $a=$b b. $ a $ b = $ b $ a c. $c=$a $ a = $ b $ b = $ c

52 Perl 2) $ a = s c a l a r @ a r r a y $ a a. @array b. @array c. 4.6.3 1) b $ a c b 2) a $ # a r r a y s c a l a r @ a r r a y 4.6.4 H a n g m a n h a n g m a

5 P e r l P e r l I / O P e r l P e r l P e r l P e r l P e r l I / O P e r l P e r l 5.1 P e r l P e r ( ) S T D I N P e r l S T D I N 2 $ @ P e r l f o r e a c h e l s e i f P e r l p e r l f u n c o p e n o p e n O p e open (filehandle, pathname) o p e n

54 Perl c :/ w i n d o w s / s y s t e m / o p e n o p e n 0 o p e u n d e f o p e n i f M Y F I L E e l s e P e r l d i e d i e P e r l s c r i p t n a m e P e r l x x x d i e d i e o p e n o p e n FA L S E O R d i e o p e n T R U E d i e O R o r c l o s e 5.1.1 n o v e l. t x t P e r l P e r l Wi n d o w s M S - D O S P e r l \ Wi n d o w s \ u s e r \ p i e r c e \ n o v e l. t x t

5 55 \ n P e r l Wi n d o w s M S - D O S / Wi n d o w s D O S U N I X / h o m e / f o o Wi n d o w s c :/ w i n d o w s / w i n. i n i U N I X../ j u n k f i l e Wi n d o w s../ b o b d i r / b o b s f i l e. t x t o p e n Microsoft Wi n d o w s U N C U N C P e r l U N C M a c i n t o s h 5-1 5-1 MacPerl M a c i n t o s h S y s t e m : U t i l s : c o n f i g M y S t u ff : f r i e n d s S h o p p i n g L i s t c o n f i g M y S t u ff f r i e n d s S h o p p i n g L i s t 5.1.2 F r e d r i c k P. B r o o k s Mythical Man-Month

56 Perl 5.1.3 die P e r l d i e d i e d i e at scriptname line xxx P e r l $! $! $! c a n n o t open myfile : a file or directory in the path does not exist $! $! $! $! P e r l w a r n w a r n d i e 5.2 P e r l < >

5 57 u n d e f U N I X ASCII 10 D O S Wi n d o w s ASCII 13 1 0 P e r l 12 M Y F I L E w h i l e w h i l P e r l $ _ w h i l e $ _ w h i l e P e r l c h o m p M Y F I L E @ c o n t e n t s n o v e l. t x t @contents:$contents [0] $content [1] 5-1 5-1

58 Perl I am the very model of a modern major-general, 5-1 1 - w 3 F H d i e 4 @ s t u ff 7 @ s t u ff 1 f o r e a c h $ _ f o r e a c h 8 $ _ s c a l a r p r i n t r e v e r s e $ _ s c a l a r r e v e r s e $ _ P e r l P e r l P e r l 5.3 > > P e r l p a t h n a m e f i l e h a n d l > > P e r l

5 59 Pe r l Windows 95/98 M a c > > > c l o s e p r i n t p r i n t p r i n f i l e h a n d l e L I S T p r i n t P e r l p r i n t P e r l P e r l No comma allowed after filehandle l o g f i l e p r i n t L O G F p r i n t

60 Perl p r i n t < S O U R C E > D E S T 5.4 P e r l 5.4.1 P e r l U N I X U N I X P e r l 3 S T D O U T S T D I N S T D E R R P e r l S T D I N p r i n t p r i n S T D O U T 12 p r i n t S T D E R R U N I X S T D E R R d i e w a r n S T D E R R Wi n d o w s D O S S T D E R R S T D O U T U N I X s h e l l U N I X 5.4.2 V M S Atari ST Wi n d o w s D O S P e r l

5 61 P e r l \ n U N I X \ n ASCII 10 L F M a c i n t o s h \ n ASCII 13 C R D O S Wi n d o w s ASCII 13 ASCII 10 C R L F G I F E X E MS word P e r l b i n m o d e b i n m o d e b i n m o d e U N I X M a c i n t o s h b i n m o d e 5.4.3 permission denied P e r l x f i l e h a n d l e p a t h n a m e 5-2 5-2 - r - r f i l e f i l e - w -w $a $ a - e - e m y f i l e m y f i l e - z - z d a t a d a t a - s - s d a t a d a t a d a t a - f - f n o v e l. t x t n o v e l. t x t - d - d / t m p / t m p - T - T u n k n o w n u n k n o w n - B - B u n k n o w n u n k n o w n - M - M f o o f o o p e r l d o c p e r l f u n c Alphabetical List of Perl Functions P e r l

62 Perl 5.5 p e r l o p e n c l o s e < > r e a d p r i n t b i n m o d e 5.6 5.6.1 o p e n o p e n o p e n > o p e n die $! ; o p e n d i e c : t a b e m p ( n e w l i n e ) o t e s. t x t o p e n P e r l P e r l o p e n p e r l permission denied P e r l P e r l P e r l g e t c 15 16

5 63 15 5.6.2 1 d a t a a. open F Hd a t aw r i t e b. open F Hd a t a F H c. open F H> d a t a die Cannot open data: $! ; 2 -M $file > 1 and -s $file a. $file b. c. $file 5.6.3 1 c a o p e n b c 2 a - M > 1 - s 5.6.4 4 H a n g m a n

6 s p l i t P e r l P e r l P e r l p e r l r e P e r l Mastering Regular Expressions J e ffery E.F. F r i e d l 1997 P e r l T C L J a v a S c r i p t P a t h o n C U N I X P e r l P e r l 6.1 P e r l m // m / s i m o n / S - i - m - o - n S i m o P e r l $ _ P e r l $ _ P e r l $ _ S - i - m - o - n m // $ _

6 65 A Z a z m // / m m / C h e e t o s / C h e e t o s / / m P e r l i f R E r e g e x p P e r l

66 Perl 6.2 6.2.1. / p. t /. p o t p a t p i t c a rp e t p yt h o n p u p _ t e n t. a p t p t e x p e c t p t 6.2.2 6-1 2 \ n \ r \ t \ f 6-1 6.2.3 / S i m o n / s S i i m m + + / d o + g /

6 67 h o u n dd o g h o td o g d o o gie howser d o o o o o og d o o g b a d g e d o o f u s D o o g i e pagoda ( o ) ( g ) D d d o g + * * 0 / t */ / c a r * t / c a r te d c a t c a r r r t c a r r o t c a r l c a a r t ( o ) ( t ) a 0 / c? o l a / c c o l a o l a o l c * / c? o l a / c o l a o l a c c o l a c / c * o l a / c o l a o l a c c o l a c 0 0 P e r l {} p a t{n, m} n m p a t n m n m / x { 5 10}/ x 5 10 / x { 9 } / x 9 / x { 0 4 }/ x 4 / x { 8 }/ x 8.* / f i r s t.* l a s t / f i r s t l a s t / f i r s t.* l a s t / first then last

68 Perl The good players get picked first, the bad last. T h e first shall be last, and the last shall be first. 3 f i r s t l a s t l a s t 4 P e r l p e r l r e 6.2.4 0 ~ 9 Von Beethoven von Beethoven v V P e r l [ ] [ a b c d e ] a b c d e [ a - e ] a b c d e G G g [ 0-9 ] [ 0-9 ] + [ A - Z a - z ]{ 5 } 5 [* # $ %&()] ^ ] ^ - ^ ] /[abc\ ] ]/ - P e r l 6-2

6 69 6-2 \ w [ a - z A - z 0-9 _] \ W \ w \ d [ 0-9 ] \ D \ s [\ t \ f \ r \ n ] \ S d o n t 6.2.5 d o g s c a t s f r o g b o g l o g f l o g c l o g / f r o g b o g l o g f l o g c l o g / P e r l o g P e r l /(fr b (f c) ) og/ 1 i s $ f r u i t $ c o l o r 6.2.6

70 Perl ^ / ^ v i d e o / v i d e o $ / e a r t h $ / e a r t h, / ^ H e l p / H e l p / ^ F r a n k l y. * d a r n $ / F r a n k l y d a r n / ^ h y s t e r i a $ / h y s t e r i a / ^ $ / / ^ / / $ / 6.3 s /// $ _ searchpattern, r e p l a c e m e n t 0 m i d d l e e n d i n a t i f a p a r t m e n t $ _ / s 6.4 6-1 6-2 M o o n 1 perl Moon

6 71 6-1 6-1 6-2 1 - w 3 ~ 4 $ _ c h o m p c h o m p $ _ 5 / ^ \ s + / $ _ 7 i f 8 ~ 9 / \s* k g s? k i l o g r a m s? / i k g k i l o g r a m s s k g k g $ _ 2. 2 11 $ _ l b s p o u n d s 1 4 $ _ 1 / 6 6.5 $ _ $ _ P e r l 6.5.1 6-2 $ _

72 Perl $ _ $ _ $ $ _ P e r l $ _ $ $ _ P e r l $ _ 8 6-2 $ w e i g h t $ _ = ~ = ~ $ _ 6.5.2 s /// m // i / m a c b e t h / i ; M a c b e t h M a C b E t H g f 4 f 4 @ F 4 f i s h f r o g f r e d f o u l g

6 73 // g w h i l e W h i l e ( letters ) $ l e t t e r s 11 9 6.5.3 P e r l P e r l $ 1 $ 2 $ 3 $ 4 / 800-555 - 1212 $ 1 $ 2 $ 3 $ 1 $ 2 $ 3 $ 1 6.5.4 grep P e r l P e r l g r e p g r e p g r e p l i s t e x p r e s s i o n b l o c k e x p r e s s i o n b l o c k $ _ g r e p @ d o g s $ _ $ _ / h o u n d / g r e p @ h o u n d s

74 Perl $ _ $ @ h o u n d s g r e y h o u n d s b l o o d h o u n d s s $ _ @ d o g s g r e y h o u n d b l o o d h o u n d s t e r r i e r m u t t c h i h u a h u a P e r l g r e p 8 g r e p U N I X U N I X g r e p U N I X P e r l to grep to grep through a book m a p g r e p m a p $ _ m a p @ words= map {split ' ',$_} @ input; @ i n p u t $ _ @ i n p u t @ w o r d s @ i n p u @ w o r d s 6.6 P e r l 6.7 6.7.1 / \w \ w + W / m // / /

6 75 / m m! p a t t e r n! / d */ * 0 \ d 2 100 1000 \ d d + / 6.7.2 1) x = y a. s/. + =. + / $ 2 = $ 1 / b. s/ * = * / $ 2 = $ 1 / c. s/ * = * / $ 2 $ 1 / 2) $ 2 $ f o o = Star Wars: The Phantom Menace $ f o o = ~ / S t a r \ sw a r sthe Phantom Menace)/ a. $ 2 b. Wa r s c. Wars:The Phantom Menace 3) m / ^ [- + ]?[ 0-9 ] + \.[ 0-9 ]*? $/ a. 04-03 - 1969 b. 45 1 5. 3-0. 61 c. 4 + 12 8 9 + 2 6.7.3 1) a c = $ 1 $ 2 = b a 2) a s t a r i $ 1 $ 2 i s t a r b 3) b + - 6.7.4

76 Perl 12 : 00 a m 5 : 00 p m 8 : 30 A M 3 : 00 2 : 60 a m 9 9 : 00 a m 3 : 0 p m 1) 2) 3) 4) 4 t h o ug h t s y ar d s ti c k

7 P e r l R o l o d w x I S B N P e r l 10 10 P e r l P e r l Perl P e r l % % a @ $ a 3 7.1

78 Perl % A u t h o r s D u n e Frank Herbert D u n e Frank Herbert $ A u t h o r s { D u n e } $ A u t h o r s {} % A u t h o r s {} % $ P e r l $ A u t h o r s { D u n e } Frank Herbert 4 P e r l = > = P e r l = > 7.2 $

7 79 % M o v i e s The Shining K u b r i c k k e y s k e y s $ f i l m keys %Movies $ f i l m $ M o v i e s { $ f i l m } k e y s P e r l v a l u e s k e y s @ D i r e c t o r s @ F i l m s % M o v i e $ D i r e c t o r s [ 0 ] $ F i l m s [ 0 ] r e v e r s e P e r l P e r l

80 Perl % B y D i r e c t o r 7.3 P e r l @ D a t a 6 0 @ D a t a % M o v i e s % M o v i e s = @ D a t a ; P e r l Perl P e r l % N e w _ H a s h = % O l d _ H a s h ; % O l d _ H a s h P e r l P e r l % N e w _ H a s h % F i r s t % S e c o n d % B o t h % F i r s t % S e c o n d % B o t h % B o t % A d d i t i o n a l

7 81 7.4 P e r l 7.4.1 k e y v a l k e y v a k e y v a l u n d e f P e r l e x i s t s e x i s t s 7.4.2 u n d e f d e l e t e %Hash=( ) 7.5 P e r l

82 Perl 7.5.1 6 $ _ w h i l e $ _ 6 g // \ w 0 [\ w -]* $ 1 $ 1 % Wo r d s P e r l 1 % Wo r d s 1 2 % Wo r d s 7.5.2 One Fish Two Fish @ f i s h w o r d s 7-1 7-1 1 % s e e n 2 $ _ 3 % s e e n $ _

7 83 5 @ u n i q u e w o r d s f i s h 7.5.3 7-2 7-2 1 % s e e n 2 $ _ 3 % s e e n 1 5 @ p o l s G r e p $ _ % s e e n $ s e e n { $ _} g r e p $ _ @ i n t e r s e c t i o n @ p o l s g r e p @ i n t e r s e c t i o n @ s t a r s @ p o l s 7-3 7-3 5 % s e e n % s e e n @ d i ff e r e n c e @ s t a r s @ p o l s

84 Perl 7.5.4 k e y s s o r t 4 s o r t A S C I I s o r t s o r t B L O C K s o r t $ a $ b s o r t $ a $ b % w o r d s $ a $ b % Wo r d s 7.6 Perl P e r l c u s t o m e r s. t e t 7-5 c u s t o m e r 1 perl Customer

7 85 7-4 C u s t o m e r 7-4 Customer 7-5 Customer 1 - w

86 Perl 3 P H c u s t o m e r s. t x t 4 ~ 5 P H $ _ $ _ c h o m p 6 $ _ \ s + s p i l t $ n u m b e r $ e m a i l 7 ~ 8 % E m a i l % P h o n e 1 0 1 3 w h i l e w h i l e 1 P e r l l a s t 1 4 ~ 1 5 1 7 ~ 2 0 2 2 ~ 23 g 2 5 ~ 28 26 n e x t 3 0 ~ 3 3 n e x t 3 4 ~ 3 5 n e x t P e r l P e r l B L O C K w h i l e d o u n t i l 7.7 D B M 7.8 7.8.1

7 87 j o i n s p l i t 13 p u s h k e y s Ti e :: I x H a s h k e y s 14 D a t a :: D u m p e r S t o r a b l e 15 D B M D B M 7.8.2 1) C u s t o m e r n a m e a. P e r l b. c. 2) a. b. c. P e r l 3) a. b. c. 7.8.3 1) b P e r l

88 Perl John Smith Robert Jones 2) a 3) c c 7.8.4 C u s t o m e r n a m e C u s t o m e r

8 p r i n t r e v e r s e s o r t o p e n c l o s e s p l i t P e r l P e r l Pe r l P e r P e r l P e r l use strict 8.1 P e r l 2 P e r l P e r l P e r l & Y e s n o ( ) ; Y e s n o ( ) ; & & y e s n o &

90 Perl P e r l P e r l 8.1.1 P e r l r e t u r n P e r l 8 t w o _ b y _ f o u r t w o _ b y _ f o u r 8 8 8 64 r e t u r n r e t u r n

8 91 8.1.2 2 4 x _ g r e a t e r t h a n 100 $ x P e r l g r e p s o r t r e v e r s e p r i n t P e r l P e r l @_ 3 @_ $ _[ 0 ] @ _ $ $ _ [ 3 ] @_ ( $ h i t s $ a t _ b a t s @_ $ _[ 0 ] $ h i t s $ a t _ b a t s @_ @_ 8.1.3

92 Perl @ i t e m s @_ @ f i r s t @ s e c o n d @_ @ f i r s t @_ @ s e c o n d @ a @ b = @_ @_ @ a @ b 4 13 8.2

8 93 $ w e i g h t $ w e i g h t m o o n w e i g h t $ w e i g h t $ w e i g h t P e r l P e r l m y m o o n w e i g h t $ w e i g h t $ w e i g h t $ w e i g h t m o o n w e i g h t $ w e i g h t m y P e r l $! $ _ @ _ m y 10 2 0 10 m y f u n c $ x $ x $ $ P e r l P e r l @_

94 Perl my M y $ y m y f o r f o r e a c h w h i l e i f m y $ s t u ff % h a s h P e r l 5. 004 f o r f o r e a c h w h i l e i f 8.3 3

8 95 68 % 95 % 8-1 s t a t s perl stats 8-1 Stats 1 - w 3 use strict m y 4 ~ 11 f o r e a c h m e a n $ s u m

96 Perl 1 2 ~ 21 m e d i a n 2 m e a n $ u p p e r $ l o w e r 2 3 ~ 32 s t d _ d e v @ d a t a $ s q _ d e v _ s u m 1 3 3 ~ 35 m y $ d a t a /[\ s,] + / $ d a t a @ d a t a s e t 3 8 ~ 40 m e a n m e d i a n s t d _ d e v s t d _ d e v m e d i a n m e a 8-2 S t a t s 8-2 Stats 8.4 P e r l use strict P e r l 8.4.1 local Perl 4 Perl Perl 5 l o c a l $ f o o m y f u n c l o c a l m y e v a l 8-1 m y f u n c $ f o o m y l o c a l

8 97 8-1 my l o c a l $ f o o m y f u n c m e s s _ w i t h _ f o o m e s s _ w i t h _ f o o $ f o o $ f o o m y f u n c 20 m y f u n c $ f o o $ f o o m y f u n c m e s s _ w i t h _ f o o $ f o o 0 $ f o o m y f u n c $ f o o m y f u n c 0 m y m y 8.4.2 Perl P e r l P e r l #! P e r l P e r l P e r l - w P e r l use strict use strict P e r l

98 Perl m y use strict P e r l m y use strict $ v a r = v a l u e ; v a l u e P e r l use strict use strict 8.4.3 A B C D E F 6 1 6 6 5 4 3 2 1 7 20 6 5 6 5 4 5 8-3 8-3 2 f a c t o r i a l $ n u m 3 f a c t o r i a l 1 0 1 1 0 $ n u m < = 1 f a c t o r i a l r e t u r n 1 4 0 1 $ n u m 6 5 4 3 2 1 4 6 5 5 4 4 3 3 2 2 1 4 f a c t o r i a l 1

8 99 1 6 f o r w h i l e f o r e a c h 8.5 P e r l P e r l P e r l 8.6 8.6.1 & $ f o o f o o p e r l s u b m y $ v a r P e r l syntax error next 2 tokens m y Perl 4 perl -v P e r l 4 13 t y p e g l o b I O :: H a n d l e l o c a l t i m e 9 1900 print "It is now ",1900+ (localtime [5] ) u n d e f (undef, undef, undef, undef, undef, $year_offset )= localtime; 8.6.2

100 Perl 1) b a r $ a, $ b $ b a. 5 b. 100 c. 68 2) foo a. 67 b. 68 c. undef 3) f o o $ b a. b. c. 8.6.3 1) b $ b f o o l o c a l $ b l o c a l m y $ b b a r $ b $ 100 2) b f o o b a r $ a $ bb a r 68 $ a b a r f o o 68 3) b l o c a l 8.6.4 7 0 1 1 2 3 5 8 0 1

9 1 0 11 1 2 P e r l 1 3 1 4 1 5 1 6Perl

9 P e r l P e r l f o r e a c h j o i n p r i n t p r i n t p r i n t 9.1 p e r l p e r l 9.1.1 index Pert index index i n d e x s t r i n g s u b s t r i n g i n d e x s u b s t r i n g o s u b s t r i n g i n d e x - 1 s u b s t r i n g P e r t

104 i n d e x 0 i n d e x s o u r c e 9.1.2 rindex r i n d e x i n d e x r i n d e x - 1 i n d e x r i n d e x r i n d e l e n g t h ( $ s o u r c e ) - 1 s t a r t 1 i n d e x 1 9.1.3 substr s u b s t r s u b s t r

9 105 s u b s t r s t r i n g o ff s e t o ff s e t l e n g t h l e n g t h o ff s e t s u b s t r s u b s t r $ a,- 5 $ a 5 l e n g t h s u b s t r l e n g t h s u b s t r 5 1 0 s u b s t r s u b s t r s u b s t r s u b s t r 9.2 s / p a t t e r n / r e p t a c e m e n t / 6 _ t r /// s e a r c h l i s t r e p l a c e m e n t l i s _ A Z A Z r e p l a c e m e n t l i s t s e a r c h l i s t t r ///

106 t r /// y /// y t r t r /// y /// s e a r c h l i s t r e p l a c e m e n t l i s t t r /// t r p e r l o p 9.3 print p r i n t P e r l p r i n t f p r i n t f C B A S I C print using p r i n t f f o r m a t s t r i n g l i s t p r i n t f p r i n t l i s t p r i n t f S T D O U T p r i n t p r i n t f f i l e h a n d l e f o r m a t s t r i n g ( ) ( ) f o r m a t s t r i n g f o r m a t s t r i n g - w. d x 9-1 Printf w d c x s w d x f 9-1

9 107 perldoc -f printf p r i n t f 0 1 0 s p r i n t f p r i n t f s p r i n t f p r i n t f s p r i n t f 9.4 9-2 E m p l o y e e 1 Perl Employee 9 1 E m p l o y e e 9-1 Employee

108 9-2 Employee 1 - w 3 use strict m y 5 ~ 11 @ e m p l o y e e s 2 3 ~ 30 @ e m p l o y e e s 2 4 1 a L 1 F m y 2 5 b L 2 L 1 2 6 ~ 29 4 4-1 3 2 ~ 34 @ e m p l o y e e s p r i n t - e m p ()

9 109 1 3 ~ 21 p r i n t - e m p () 1 4 ~ 15 $ _[ 0 ] l a s t f i r s t 1 7 1 8 ~ 20 h o u r s t i m e. 005 9.5 0 1 2 3 4 5 Klondike Solitaire 7 P e r l p u s h p o p S h i f t u n s h i f t p o p s h i f t t a rg e t _ a r r a y t a rg e t _ a r r a y @_ @ A R G V p o p s h i f t

110 u n d e f p o p s h i f t u n s h i f t p u s h @_ @ A R G V p u s h u n s h i f t n e w _ l i s t t a rg e t _ a r r a y t a rg e r _ a r r a y t a rg e t _ a r r a y p u s h (@ l i s t @ n e w i t e m s ) @ l i s t = (@ l i s t @ n e w i t e m s ) P e r l p u s h s h i f t u n s h i f t p u p 0 s p l i c e s p l i c e s p l i c e o ff s e t o ff s e t l e n g t h l e n g t h l i s t l e n g t h l i s t 9.6

9 111 i n d e x r i n d e x t r /// s u b s t r p r i n t f s p r i n t f P e r l 9.7 9.7.1 s u b s t r i n d e x r i n d e x i n d e x r i n d e x s u b s t r P e r l s u b s t r i n d e x r i n d e x use of undefined value a = F o o s u b s t r a, 5 s u b s t r u n d e f 9.7.2 1) @ A a. oats peas beans b. deans barley c. peas beans barley 2) printf ( % 18. 3 f a ) a. 18 15 3 b. 18 3 c. 18 14 3 3) t r / a - z / A - Z t r / A - Z / a - z a. b.

112 9.7.3 1) c s h i f t c a t s p u s h b a r l e y p o p array @_ @ A 2) c a 18 1 4 1 3 3) b t r / a - z / A - Z / r o s e b u d R O S E B U D t r / A - Z / a - z / r o s e b u d 9.7.4 4 H a n g m a n s u b s t r 9-2

1 0 M a c i n t o s h P e r l P e r l u n i x P e r l P e r l P e r P e r l 10.1 o p e n d i r d i r h a n d l e d i r e c t o r y o p e n d i r 2 P e r l U N I X U N I X Wi n d o w s

114 r e a d d i r r e a d d i r u n d e f r e a d d i r r e a d d i U N I X r e a d d i r... r e a d d i r c l o s e d i r @ F I L E S... / ^ \.\.? $ / g r e p r e a d d i r o p e n d i r / t m p o p e n ( F I L E H $ f i l e ) / t m p m y f i l e. t x t r e a d d i r m y f i l e. t x t m y f i l e. t x t / t m p / m y f i l e. t x t Globbing g l o b b i n g D O S d i r *. t x t. t x t U N I X g l o b b i n g s h e l l l s *. t x t. t x P e r l g l o b G l o b giob p a t t e r n p a t t e r n p a t t e r n p a t t e r n 10-1 g l o b g l o b

10 115 g l o b 10-1 globbing f d f u d f i d f d d f * d f d f d d f o o d f i l l e d [ c h a r s ] c h a r s ; f [ o u ] d f o d f u d f a d M a c P e r l { a b } a f *{ t x t d o c } f. t x t. d o c b M a c P e r l U N I X P e r l g l o b C s h e l l g l o b b i n g B o u r n e K o r n s h e l l g l o b b i n g P e r l U N I X s h e l l Bourne shell g l o b b i n g Korn shell globbing C shell globbing *? g l o b b i n g g l o b opendir/readdir/closedir g l o b g l o g l o b s h e l l o p e n d i r / r e a d d i r / c l o s e d i r g l o b o p e n d i r / r e a d d i r / c l o s e d i r g l o b / u s r / i n c l u d e / *. h / u s r / i n c l u d e r e a d d i r g l o b o p e n d i r / r e a d d i r / c l o s e d i r P e r l g l o b b i n g o p e n d i r / r e a d d i r / c l o s e d i r

116 P e r l g l o b < > g l o b g l o b b i n g g l o b 10.2 UNIX grep U N I X g r e p U N I X g r e p P e r l g r e p 10-1 m y g r e p 1 U N I X g r e p g r e p perl mygrep 10-1 mygrep 1 - w 3 use strict m y 5 ~ 8 $ d i r $ p a t S T D I N

10 117 1 0 $ f i l e use strict $ f i l e 1 2 $ d i r 1 3 1 $ f i l e 1 4 - d $ d i r / $ f i l e $ f i l $ d i r $ d i r / $ f i l e 1 5 ~ 18 $ d i r / $ f i l e 1 9 ~ 23 $ p a t 10-2 m y g r e p 10-2 mygrep 10.3 r e a d d i r P e r l 10.3.1 U N I X p w d s h e l l D O S Wi n d o w s C :\ W I N D O W S D O c d D O S / P e r l P e r l P e r l c w d o p e n F Hf i l e d i e c h d i r chdir newdir; c h d i r n e w d i n e w d i r n e w d i c h d i r c h d i r P e r l

118 P e r l c h d i r c h d i U N I X Windows 95 Wi n d o w s N T D O S c h d i r H O M E H O M c h d i r P e r l use Cw d c w d use Cwd c w use Cwd P e r l Cw d P e r l C w d Ca n t locate cwd.pm in @INC @ I N C C w d. p m 14 10.3.2 P e r l m k d i r m k d i r n e w d i r m k d i r m k d i r P e r l U N I X p e r m i s s i o n s p e r m i s s i o n s 0755 U N I X D O S Wi n d o w s 0755 r m d i r r m d i r p a t h n a m e r m d i r P a t h n a m e r m d i r r m d i r r m d i r

10 119 10.3.3 u n l i n k u n l i n k l i s t _ o f _ f i l e s l i s t _ o f _ f i l e s _ u n l i n k $ e r a s e d u n l i n k $ e r a s e d @ f i l e s u n l i n k u n l i n k 10.3.4 P e r l r e n a m e r e n a m e o l d n a m e n e w n a m e o l d n a m e n e w n a m e r e n a m e r e n a m e n e w n a m e r e n a m e

120 10.4 UNIX P e r l U N I X U N I P e r l U N I X U N I X P e r l U N I X P e r l U N I X u n l i n k U N I X U N I X P e r l u n l i n k P e r l I / O P e r l U N I X P e r l U N I X U N I X U N I U N I X U N I X UNIX 24 1 P e r l chmod 755 scriptname 755 s c r i p t n a m e U N I X c h m o d 7 7 5 7 5 10-2 10-2 1 P e r l U N I X c h m o d c h m o d l i s t _ o f _ f i l e s m o d e 0

10 121 c h m o d m k d i r m k d i r c h m o d U N I X c h m o d c h a n g e m o d e 10.5 P e r l s t a t s t a t U N I X U N I U N I X S t a t s t a t s t a t 13 10-3 s t a t 10-3 stat U N I X Wi n d o w s 0 d e v C 2 D 1 i n o 0 2 m o d e 3 3 n l i n k 0 Windows NT 4 u i d I D U I D 0 5 g i d ID G I D 0 6 r d e v 7 s i z e 8 a t i m e 9 m t i m e 1 0 c t i m e I n o d e 11 b l k s z 0 12 b l o c k s 0 1 0-3 U N I X s t a t

122 s t a t 3 @ s t u ff m o d e s t a t & 0777 0 p r i n t f 0 ~ 7 U N I X 8 U N I X P e r l p r i n t f 1 0-3 3 1970 1 1 l o c a l t i m e Sat Jul 3 23:35:11 EDT 1999 U N I X Microsoft Wi n d o w s c t i m e s t a t 1 s t a t 10.6 C h a p t e r _ 01. r t f C h a p t e r _ 02. r t f C h a p t e r _ 04. r t f H o u r _ 01. r t f H o u r _ 02. r t f H o u r _ 04. r t f 10-3 R e n a m e r 1

10 123 10-3 Renamer 1 3 ~ 15 $ d i r @ f i l e s 1 7 ~ 19 @ f i l e s _ o l d n a m e _ 19 2 0 2 1 ~ 2 5 $ / d i r / $ o l d n a m e @ f i l e s 10-4 10-4 Rename 10.7 P e r l m k d i r r m r e n a m e s t a t

124 10.8 10.8.1 2 D I R H A N D L E @files=readdir DIRHANDLE g l o b ( *.* ) *.* g l o b (*.*) g l o b D O S *.* m y g r e p o p e n d i r 15 F i l ef i n d *. b a t *. t m p 10-3 *. b a t *. b a * \*\. b a t * 19 s /\ Q $ o l d p a t / $ n e w p a t / 10.8.2 1) f o o f i l e a. print glob( f o o f i l e ) b. print (stat( f o o f i l e ) ) [ 9 ] ; c. print scalar localtime (stat ( f o o f i l e ) ) [ 9 ] 2) unlink a. b. c. 10.8.3 1) b c b 1970

10 125 c 2) a c u n l i n k 0 10.8.4

11 P e r l P e r l P e r l P e r l system() Wi n d o w s D O S U N I X 11.1 system() P e r l s y s t e m () s y s t e m () P e r l P e r l s y s t e m c o m m a n d 0 Tr u e F a l s e P e r l U N I X s y s t e m D O S Wi n d o w s s y s t e m

11 127 s y s t e m D O S d i r U N I X l s p e r l d o c U N I X D O S s y s t e m P e r l P e r l s y s t e m S T D I N S T D O U T P e r l s y s t e m U N I X Wi n d o w s D O S m y f i l e. t x t U N I X v i D O S e d i t P e r l s y s t e m U N I X D O S Wi n d o w s s y s t e m P e r l s y s t e m s h e l l U N I X / b i n / s h D O S Wi n d o w s c o m m a n d. e x e s y s t e m s h e l l U N I X & p e r l d o c p e r l f a q 5 f a q f i l e. t x t D O S U N I X U N I X

128 x t e r m & U N I X s h e l l s y s t e m P e r l P e r l x t e r m U N I X P e r l b i n / s h s y s t e m s h e l l U N I X s y s t e m M a c i n t o s h M a c P e r l M a c i n t o s h 11.2 s y s t e m P e r l s y s t e m o u t f i l e @ d a t a d i r P e r l ` ` P e r l s y s t e m d i r $ d i r e c t o r y s h e l l > U N I X & > @ d i r f o r e a c h P e r l q x {} {}

11 129 {} < > [] shell P e r l U N I X D O S Wi n d o w s $ H O M E P e r l $ H O M E s h e l l $ H O M E D O S % w i n d i r % c o m m a n d. c o m w i n d i r P e r l % w i n d i r % $ H O M E P e r l $ H O M E P e r $ H O M E % w i n d i r P e r l $ H O M E UNIX shell H O M E % w i n d d i r % c o m m a n d. c o m w i n d d i r q x {} q x P e r l qx P e r l 11.3 U N I X D O S Wi n d o w s U N I X d i r l s D O S

130 d i r o u t f i l e s o r t o u t f i l e s o r t n e w f i l e m o r e n e w f i l e o u t f i l e n e w f i l e d i r s o r t s o r t s o r t m o r e 1 > U N I X D O S Wi n d o w s P e r l P e r To t a l e r P e r l U N I X dir /B ls -1 11-1 To t a l e r 11-1 To t a l e r 6 S T D I N $ _ S T D I N S T D O U T S T D I N dir B 9 ~ 13 $ d i r s 1 4 ~ 15 $ s i z e s 1 7 ~ 1 8 P e r l P e r l o p e n o p e n dir/b sort P e r l

11 131 o p e n P e r l dir /B sort R H A N D L E s o r t P e r l o p e n m o r e P e r l W H A N D L E m o r e 1 R H A N D L E W H A N D L E o p e n c l o s e P e r l c l o s e c l o s e o p e n U N I X P e r l c l o s e 11.4 P e r l P e r V M S U N I X M a c i n t o s h M S D O S P e r l P e r l P e r l P e r l 16 P e r l Wi n d o w s D O S U N I X Wi n d o w s U N I X Wi n d o w s U N I X MacOS 9 Windows NT U N I X P e r l Windows NT P e r l U N I X We b

132 use strict P e r l open die o p e n P e r l s y s t e m ` ` I O I O 8 use strict 3 m y s c r i p t. p l F o o f i l e. t x t 24 4 P e r l $ d i r = ` d i r ` Wi n d o w s < * > o p e n d i r / r e a d d i r / c l o s e d i r P e r l P e r Amazon.com web P C Windows NT Sun 1000 UNIX C G I We b Windows NT U N I X P e r l

11 133 $ ^ O ^ O Wi n d o w s D O S M S Wi n 32 U N I X U N I X l i n u x a i x s o l a r i s e m a i l Wi n d o w s @ d i r bytes free $ f r e e Wi n d o w s U N I X L i n u x Wi n d o w s d i r U N I X df -k. df -k 4 $ f r e e d f U N I X P e r l

134 D O S Wi n d o w s L i n u x f r e e s p a c e () U N I X O S 11.5 s y s t e m ` ` P e r l o p e n p r i n t < > 11.6 11.6.1 open (P cmd )

11 135 c m d < P > c m d print P... P e r l C a n t do bidirectional pipe I P CO p e n 2 14 $ a = s y s t e mc m d $ a c m d s y s t e m ` ` s y s t e m c m d $ a = ` c m d ` U N I X ` ` U N I X P e r l S T D O U T S T D E R R S T D O U T S T D E R R o p e n S T D O U T s h e l l S T D O U T S T D E R R P e r l FA Q perldoc perlfaq8 FA Q 11.6.2 1) 1 2) $foo $r=`dir $foo` a. $foo s h e l l b. Perl $ f o o d i r 3) a. b. c. 11.6.3 1) a b a m y p r o g. p l m o r e b M m o r e 2 ) b $ f o o P e r l qx`dix $foo` 3) a b g l o b < * > o p e n d i r r e a d d i r C r m d i r

136 11.6.4 8 11-1 U N I X U N I X f r e e s p a c e () L i n u x

1 2 P e r l P e r l P e r l P e r l P e r l P e r l P e r l P e r l P e r l P e r l 12.1 P e r l P e r l P e r 12.1.1 P e r l D O S Wi n d o w s M S - D O S C :\ U N I X P e r l M a c i n t o s h S c r i p t D e b u g g e r D e b u g g e r 9 9-2 E m p l o y e e D O S P e r l - d P e r l

138 1. 0401 help ( ) 7 my @employees= 7 E m p l o y e e 5 11 D B < 1 > 1 P e r l -my @employees=( 12.1.2 h e l p h h h cmd h P e r l P e r l n n P e r l E m p l o y e e 5 11 m y ( $ L 1 $ F 1 ) = s p l i t $ a @ e m p l o y e e s 5 P e r l @ e m p l o y e e s

139 12 Perl n 23 P e r l s o r t s o r t n s o r t E n t e r 12.1.3 P e r l l 10 l 10 l l i n e n o l i n e n o l start-end = = = > 33 s o r t P e r l P e r l 30 29 31 b breakpoint b r e a k p o i n t

140 33 c c P e r l P e r l 33 p r i n t - e m p c p r i n t _ e m p () 33 L print_emp ( ) E m p l o y e e 33 d d line d s u b n a m e 12.1.4 p r i n t - e m p () R

141 12 Perl R P e r l P e r l 33 n p r i n t - e m p () p r i n t - e m p () n s n s 1 p r i n t _ e m p () 1 b print_emp p r i n t _ e m p () n P e r l 2. 50 $ h o u r l y 10 1 5 2. 50 P r i n t f $ h o u r l y q 12.2 12-1

142 12-1 P e r l use strict P e r l 12-1 Buggy 12.3 P e r l P e r l M a c i n t o s h S c r i p t l - l i n e r s 12.3.1 One-Liners P e r l - e - e P e r l - e

143 12 Perl Wi n d o w s / D O S c o m m a n d. c o m N T S h e l l p r i n t Hello Wo r l d > < ^ D O S / Wi n d o w s U N I X \ UNIX shell(csh k s h b a s h ) s h e l l s h e l - e - d P e r l P e r l 1 P e r l 1 1 12.3.2 P e r l - c P e r l P e r l - w - c P e r l P e r l P e r l P e r Perl 5 - v

144 P e r l 5. 004 _ 02 - v P e r l @ I N C P e r l P e r l P e r l 14 12.3.3 < > 1) < S T D I N > 2) g l o b < *. b a t > P e r l E x a m p l e. p l < > f i l e 1 1 f i l e 2 f i l e 3 S T D I N U N I X S e d a w k P e r l P e r - w - c - d - e @ A R G V $ A R G V [ 0 ] f i l e 1 $ A R G V [ 1 ] f o l e 2 P e r l - n - e

145 12 Perl P e r l f i l e 1 w h i l e $ _ 1 S / ^ \ S + // g - p - n P e r l d o s f i l e P e r l d o s f i l e > d o s f i l e P e r l o n e - l i n e r s Perl Journal P e r l 12.4 P e r l < > P e r l P e r l - n - p P e r l 12.5 12.5.1 P e r l Wi n d o w s P e r l A c t i v e s t a t e m a i n

146 P e r l P e r l perldoc perlrun 12.5.2 1) 12-1 2) < > a. undef b. c. Tr u e 3) Prel P r e l a. T b. t 12.5.3 1) 15 20.. 0.. f o r $ _ = 20 $ _ > - 1 $ _- 0.. 20 10 $ m e s s = s / g l a s s e s / g l a s s / $ m e s s $ _ = = ~ 2) b < > S T D I N 3) b t T

1 3 P e r l p a s c a l C B A S I C J a v a P e r l P e r l P e r P e r l 13.1 $ a S t o n e s $ a $ b $ a $ a = $ b $ a $ b

148 $ r e f $ a $ r e f $ r e f $ a $ a $ a = F o o (print $a) $ r e f $ a $ r e f $ r e f S C A L A R ( 0 x 0000 ) $ r e f $ a $ r e f $ r e f $ a $ $ r e f $ P e r l $ r e f $ r e f $ a $ r e f $ $ r e f $ r e f $ r e f $ $ o r e f $ $ n r e f G a n d a l f

13 149 $ b r e f 2 $ $ b r e f $ b r e f $ $ b r e $ $ $ b r e f 2 13.1.1 $ a r e f @ a r r $ a r e f @ a r r $ $ a r e f [ 0 ] @ a r r @ $ a r e f [ 2 3 ] @ $ a r e f @ a r r @ a r r $ $ a r e f [ 0 ] $ { $ a r e f } [ 0 ] $ $ a r e f [ 2 3 ] $ { $ a r e f } [ 2 3 ] @ $ a r e f @ { $ a r e f } $ a r e f @ a r r 13.1.2 % h a s h $ h r e f % h r e f % h a s h $ $ h r e f { k e y } % h a s h $ { $ h r e f }{ k e y } % $ h r e f %{ $ h r e f }

150 13.1.3 8 g e t a r r a y s (@ f r u i t @ v e g g i e s ) @_ g e t a r r a y s () @ a @ b @_ @ @ f r u i t s @ v e g e t a b l e s @ a @_ g e t a r r a y s g e t a r r a y s () $ f r u i t _ r e f $ v e g _ r e f

13 151 @_ % h a s h c h a n g e h a s h () @_ % l o c a l _ h a s h % l o c a l _ h a s h % l o c a l _ h a s h % h a s % h a s h @_ c h a n g e h a s h () $ h r e f % h a s h $ h r e f c h a n g e h a s h () % h a s h b e a r @_ @ 13.1.4 P e r l % h a s h $ h r e f % h a s h % h a s $ h r e f % h a s h $ h r e f P e r l % h a s h $ a h r e f {}

152 [] use strict P e r l $ r e f use strict P e r l - w undefined value 13.2 13.2.1 P e r l 1 2 3 4 0

13 153 P e r l P e r l @ l i s t _ o f _ l i s t s $ # $ l i s t _ o f _ l i s t s [ 1 ] @ l i s t _ o f _ l i s t s A R R AY 0 x 00000 @ l i s t _ o f _ l i s t s @ 13.2.2 P e r l P e r l Perl Data Structures Cookbook(Perl ) Perl Data Structures Cookbook

154 Perl Data Structures Cookbook perldoc perldsc 13.2.3 P e r l P e r l $ m y s t e r y _ r e f e r e n c e S C A L A R H A S H C O D E $ m y s t e r y _ r e f e r e n c e P e r l $ r e f $ r e f x f r u i t v e g e t a b l e $ a A R R AY 0 x 20170 b d 4 3 A R R AY 0 x 20115484 A R R AY 0 x 2011 f b b 4 A R R AY

13 155 0 x 2011 f a a 0 3 D a t ad u m p e r D a t ad u m p e P e r l D a t ad u m p e r 14 13.3 13-2 M a z e 13-1 13-1 Maze 13-2 Maze

156 1 ~ 2 P e r l - w use strict 4 ~ 9 @ m a z e 4 4 2 1 - n s e w 1 0 ~ 11 % d i r e c t i o n x - 1 y x 1 33 ~ 34 1 3 ~ 15 m y use strict $ c u r r _ x $ c u r r _ y 0 0 $ x $ y 3 3 1 7 x y 2 0 $ m a z e [ $ c x ][ $ c y ] n s e w 1 % f u l l n s e w ( n )

13 157 ( N o r f h ) 2 5 $ n e w 2 8 l c s u b s t r $ n e w E a s t e We s t w s 2 9 $ m a z e [ $ $ x r e f ][ $ $ y r e f ] n s e w 3 3 ~ 34 x y e $ d i r e c t i o n { e } 0 1x 0 $ d i r e c t i o n { e }[ 0 ] Y 1 $ d i r e c t i o n { e }[ 1 ] 3 7 x y $ c u r r _ x $ c u r r _ y $ x $ y 3 8 3 9 $ m o v e c h o m p q 4 2 m o v e _ t o () m o v e _ t o () $ c u r r _ x $ c u r r _ y @ m a z e P e r l $ x $ y 13.4 P e r l 13.5 13.5.1 p r i n t @ L O L A R R AY 0 x 101210 A R R AY 0 x 1 0 1 4 0 0 p r i n t @ a r r a y P r i n t @ L O L @ L O L @ L O $ r e f = \( $ a $ b $ c ) P e r l \ $ a $ b $ c \ $ a \ $ b \ $ c $ c

158 $ r e f = [ $ a $ b $ c ] 13.5.2 1) $ r e f = \ p e a n u t s $ r e f a. b. peanuts c. 2) 13.5.3 a. b. c. 1) c $ r e f = \ 100 a 2) b k i d s 13.5.4 M a z e 4 n e n w s e s w @ m a z e % d i r e c t i o n [ 1 1 ][- 1-1 ]

1 4 P e r l P e r l P e r l s y s t e m world wide w e b 10 w e b P e r l Perl 5 P e r l P e r l w e b Windows OLE P e r l P e r l P e r l C G I P e r l 3500 20 P e r l P e r l 14.1 P e r l P e r l u s e C w d use Cwd; use Cwd 10 10

160 use Cwd 1) Perl use Cwd 2) P e r l C w d P e r l 3) Perl 4) Perl P e r l use strict use Cwd u s e P e r l u s e s t r i c t s t r i c t use Cwd use Cwd c w d c w d 14.1.1 P e r l p e r l d o c C w d 1

14 161 C w d 3 c w d g e t c w d f a s t g e t c w d C w d P e r l C w d C w d. p m P e r l @ I N C C w d. p m perl -v P e r l T K L M P 16 14.1.2 P e r l P e r l perl -v P e r l 5 4. 036 P e r l Perl 5 13 Perl 4 3 Use Cwd use cwd F i l ef i n d P e r l 150 P e r l

162 P e r l @ I N C P e r l 14.2 P e r l 14.2.1 10 i m p o r t a n t. d o c d o c u m e n t s o p e n d i r / r e a d d i r / c l o s e d i r d o c u m e n t s d o c u m e n t s d o c u m e n t s a c c o u n t i n g m i s c p e r s o n a l 30 P e r l F i l e F i n d F i l ef i n d f i n d f i n d f i n d & d i r l i s t 14-1 i m p o r t a n t. d o c 14-1

14 163 1 2 P e r l - w use strict 3 F i l e Fi n d f i n 5 / d o c u m e n t s 100 12 112 6 w a n t e d () $ F i l ef i n dn a m e $ _ i m p o r t a m t. d o c 1 0 \& w a n t e d f i n d / d o c u m e n t s w a n t e d () f i n d $FileF i n dname $FileF i n ddir $_ $ _ 14-2 F i l ef i n d C D. t m p U N I X 14-2 14-2 14-1 7 9 11. t m p. t m p

164 u n l i n k 14.2.2 P e r l 1) 2) 3) 4) P e r l F i l ec o p y s o u r c e f i l e d e s t i n a t i o n c o p y 1 0 $ F i l ec o p y m o v e m o v e i m p o r t o n t. d o c d :/ a r c h i v e s / d o c u m e n t s m o v e m o v u n l i n k 14.2.3 Perl P e r l N e tp i n g N e tp i n g U N I X p i n g p i n g p i n g p i n g N e tp i n g N e tp i n g p i n g e c h o

14 165 w w w. y a h o o. c o m p i n g e c h o P e r l Windows 95/98 N T 1 999 N e tp i n g N e tp i n g a l a r m Wi n d o w s A c t i v e s t a t e Wi n d o w s P e r l Wi n d o w s P e r l 14.2.4 English E n g l i s h P e r l while(< >) S T D I N $ _ use English $ _ $ A R G E n g l i s h 14.2.5 diagnostics P e r l d i a g n o s t i c s P e r l P e r l d i a g n o s t i c s P e r l

166 P e r l h e l p \@ s u p p o r t. c o m use strict @ s u p p o r t m y @ s u p p o r t P e r l W D S ( F ) F P e r l P e r l 60 P e r l use diagnostics p e r l d i a g 14.3 P e r l P e r p e r l d o c A u t o L o a d e r A u t o S p l i t B e n c h m a r k C G I C PA N C a r p D i r H a n d l e E n v E x p o r t e r E x t U t i l s* F i l e* F i l es p e c* F i l e C a c h e F i n d B i n G e t o p t* P e r l P e r l We b Common Gateway Interface ( 17 ~ 24 ) P e r l F i l ec o p y

14 167 ( ) I 18 NC o l l a t e I P C* M a t h* N e t* P o d* S y m b o l S y sh o s t n a m e S y ss y s l o g Te r m* Te x ta b b r e v Te x tp a r s e Wo r d s Te x ts o u n d e x Ti e* Ti m e* c o n s t a n t i n t e g e r L o c a l e N e th o s t e n t I P 204. 71. 200. 68 w w w. Ya h o o. c o m P e r l Plain Old Documentation P e r l I P U N I X S o u n d e x P e r l Sat Jul 24 16:21:38 EDT 1999 1970 1 1 P e r l We b h t t p / / w w w. c p a n. o rg C Wi n d o w s A c t i v e s t a t e P e r l P P M U N I X Wi n d o w s C PA N U N I X A c t i v e s t a t e P P M 14.4 P e r l P e r l P e r l 14.5 14.5.1 F i l ef i n d $ F i l ef i n d d i r P e r l

168 C w d $ C w dx $ m a i nx $ x Windows 95/98/NT A c t i v e s t a t e P P M C PA N U N I X Wi n d o w s C r e q u i r e u s e P e r l r e q u i r e r e q u i r e u s e Perl 4 u s e r e q u i r e r e q u i r e u s e r e q u i r e r e q u i r e u s e 14.5.2 1) c w d use Cwd; a. b. cwd c. c w d 2) $ _ a. LongVa r s b. English c. $_ 14.5.3 1) a u s e 2) b use English $ _ $ A R G 14.5.4 C PA N B u n d l elw P 2 4

1 5 P e r l D B M 15.1 DBM D B M D B M P e r l D B M 7 D B M P e r l d b m o p e n d b m o p e n h a s h D B M f i l e n a m e f i l e n a m e. p a g f i l e n a m e. d i r P e r l m o d e P e r l D B M U N I X D B M 0666 D B M mode 0644 Wi n d o w s 0666 D B M d b m o p e n % h a s h d b m f i l e D B M P e r l d b m f i l e. p a g d b m f i l e. d i r P e r l D B M

170 P e r l D B M D B M d b m c l o s e D B M f e l i n e c a n i n e D B M D B M P e r l D B M D B M k e y s v a l u e s d e l e t e D B M % h a s h = () d b m o p e n D B M 15.1.1 D B M D B M 1024 D B M d b m o p e n d b m o p e n % h d r o m e d a r e dbmclose D B M D B M D B 15.1.2 DBM D B M P e r l P e r l

15 171 D B M r e c o r d s D B M keys %recs foreach my $key % r e c s keys %recs P e r l e a c h e a c h e a c h e a c h e a c h e a c h D B M e a c h 15.2 15-2 m e m o p a d 15-1 m e m o p a d m e m o p a d X is Y X Y like pattern p a t t e r n q u i t 15-1 m e m o p a d

172 m e m o p a d D B M 15-2 memopad 1 ~ 2 P e r l - w use strict 6 d b m o p e n % a n s w e r s D B M a n s w e r s a n s w e r s. p a g a n s w e r s. d i r 7 w h i l e ( 1 ) l a s t e x i t 9 l c < S T D I N > S T D I N

15 173 $ _ c h o m p 1 0 q u i t w h i l e 11 $ _ l i k e $ 1 1 2 11 $ p a t t e r n 1 3 1 7 % a n s w e r s $ p a t t e r n 1 8 11 i f $ 1 1 9 $ 1 $ s u b j e c t 2 0 2 4 $ s u b j e c t % a n s w e r s I don t know 2 5 2 7 11 i f X is Y X $ s u b j e c t $ i n f o 2 8 $ i n f o $ s u b j e c t % a n s w e r s 3 4 D B M % a n s w e r s 15.3 We b D B M O r a c l e S y b a s e

174 [ s p a c e ] [ n e w l i n e ] P e r l Susan 555-6613 B o b M a u r y D B M p h o n e. t x t P e r l

15 175 r e a d d a t a () p h o n e. t x t @ D ATA Wr i t e d a t a () r e a d d a t a () p u s h u n s h i f t s p l i c e w r i t e d a t a () @ P H O N E L I S T S p l i c e p o p s h i f t, g r e p r e a d d a t a () @ P H O N E L I S T g r e p @ P H O N E L I S T A n n @ P H O N E L I S T @ P H O N E L I S T w r i t e d a t a () 15.4 15.4.1 3 15-1 U N I X + >

176 15-1 o p e n o p e n F< f i l e o p e n (F: file ) o p e n ( F> f i l e ) o p e n ( F> > f i l e ) o p e n ( F+ < f i l e ) o p e n ( F+ > f i l e ) o p e n ( F+ > > f i l e ) 15.4.2 s e e k s e e k 0 1 2 t e l l t e l l ( F ) 24 This is at the beginning s e e k t e l l o p e n s e e k t e l l o p e n p e r l f u n c perldoc perlfunc p e r l f u n c p e r l o p e n t u t o p e n perldoc perlopentut 15.5 P e r l U N I X

15 177 Windows NT Windows 95 Windows 98 We b P e r l 2 D a v i d 3 @ P H O N E L 4 2 3 J o y 4 @ P H O N E L 5 2 3 D a v i d 1 2 J o y @ P H O N E L D a v i d 1 @ P H O N E L D a v i d 2 1 J o y D a v i d w r i t e d a t a ()

178 15.5.1 UNIX NT U N I X Windows NT P e r l f l o c k f l o c k f l o c k f l o c k f l o c k f l o c k f l o c k use Fcnt1 qw( f l o c k ) l o c k _ t y p e l o c k _ t y p e lock_sh f l o c k Lock_EX f l o c k Lock_UN f l o c k

15 179 o p e n F H, > f i l e n a m e f l o c k > 15-3 15-3 g e t _ l o c k () r e l e a s e _ l o c k () 15.5.2 r e a d d a t a () w r i t e d a t a () g e t _ l o c k () r e l e a s e _ l o c k () 15-4 15-4

180 15-4 g e t _ l o c k () r e l e a s e _ l o c k ( ) r e a d d a t a ( ) writedata () g e t _ l o c k () r e a d d a t a () @ P H O N E L w r i t e d a t a () r e l e a s e _ l o c k ( ) 15.5.3 Windows 95 Windows 98 Windows 95 Windows 98 Windows 95 Windows 98 f l o c k

15 181 g e t _ l o c k () r e l e a s e _ l o c k () Windows 95 Windows 98 f l o c k 15.5.4 f l o c k f l o c k U N I X N F S f l o c k U N I X Windows NT U N I X f l o c k f l o c k P e r l FA Q f l o c k perlfaq 5 15.6 P e r l D B M D B M 15.7 15.7.1 13 D B M D B M D a t ad u m p e r D B M D B M 15-3 g e t _ l o c k () r e l e a s e _ l o c k () D B M o p e n c l o s e f l o c k f l o c k f l o c f l o c k L o c k _ N B

182 15.7.2 1) D B M a. b. 2) a. b. c. 3) FA Q 15.7.3 1) b D B M 1024 2) a c 3) FA Q 5 15.7.4 1

1 6P e r l P e r l P e r l P e r l P e r l P e r l P e r l C PA N 16.1 Perl P e r l P e r l 16.1.1 Perl 1988 I n t e r n e t I n t e r n e t 6 1 Wold Wide We b 1991 C E R N World Wi d e We b 1993 M o s a i c I n t e r n e t U s e n e t I n t e r n e t 1988 1 Larry Wa l l U N I X a w k s e d P e r lp e r l P e r l C s e d a w k s h P e r l c s h P a s c a l B A S I C P L U S P e r l C

184 s e d a w k s h s e d a w k s h C P e r l s e d a w k P e r l P e r l 1988 6 P e r l Perl 2 P e r l P e r l P e r l 1991 Larry Wa l l Randal Schwartz Programming Perl P e r P e r l Perl 4 Perl 4 P e r l 1992 I n t e r n e t 1994 1 0 Perl 5 1996 1 0 Programming Perl 16.1.2 P e r l P e r l P e r L i n u x F r e e B S D Apache We b N e t s c a p e M o z i l l a Eric S Raymond (The Cathedral and the B a z a a r ) U R L Larry Wa l l P e r l P e r l P e r l Larry Wa l l G N U

16Perl 185 P e r l P e r l P e r l P e r l P e r P e r l P e r l P e r l P e r l P e r l P e r l P e r l P e r l P e r l A r t i s t i c ( ) h t t p :// w w w. g n u. o rg G N U P e r l P e r l 16.1.3 Perl P e r l Perl P e r l P e r Larry Wa l l P e r l P e r l 1999 8 ( m a j o r. m i n o r _ p a t c h l e v e l 4 0 36 1 8 P e r l 4 36 18 P e r l 1999 P e r l 5 0 05 P e r l 5. 6 Perl 5.6 5. 7 16.2 Perl CPAN P e r l C PA N

186 16.2.1 CPAN P e r l C PA N P e r l P e r l C PA N C PA 4 3500 16-1 CPAN T K N e t* M a t h* D a t e* Ti m e D a t e* Tr e e* D B I* D B D* Te r m* S t r i n g* Te x t* C G I* U R I* H T M L* LW P* G D G r a p h i c s* I m a g e* Wi n 3 2* Wi n 3 2 A P I* 16-1 CPA N P e r l Win32 API G t k G n o m e Q t X I I M a i l Te l n e t I R C L D A P 4 0 30 * B - O r a c l e i n f o r m i x I n g r e s O D B C M s q I M y s q l S y b a s e D O S C o m m a n d U N I X We b Microsoft Wi n d o w s C PA N C PA N R E A D M E P e r l P e r G N U C PA N P e r l C PA N 16.2.2 5 0

16Perl 187 C PA N P e r l P e r l C PA N C PA 16.3 P e r l 5 6 P e r l 2300 P e r l 16.3.1 P e r l 16.3.2 P e r l P e r l P e r l P e r l

188 P e r l P e r l P e r l 1) - w 2) use strict - w use strict 16.3.3 p r i n t p r i n t p r i n t D E B U G S T D E R R _ L I N E _ _ F I L E _ P e r l P e r l P e r 12 P e r l 16.3.4 P e r l

16Perl 189 1 P e r l Perl 5.005 1700 P e r l perldoc perl P e r l P e r l P e r l p e r l d o c P e r l h t t p / / w w w. p e r l. c o m 16.3.5 U s e n e t 80 I n t e r n e t U s e n e t P e r l c o m p. l a n g. p e r l. a n n o u n c e c o m p. l a n g. p e r l. m o d e r a t e d comp.lang perl.misc P e r l P e r l P e r l U s e n e t We b d e j a. c o m S u p e r n e w s. c o m We b U s e n e t We b P e r l P e r l d e j a. c o m U s e n e t We b P e r l d e j a. c o m P o w e r S e a r c h 100 U s e n e t

190 d e j a. c o m 5 16.3.6 U s e n e t U s e n e t We b 1) P e r l P e r l d e j a. c o m 2) P e r l comp.lamg. perl.misc C G I c o m p. i n f o s y s t e m s. w w w. a u t h o r i n g. c g i 3) 4) a. b. c. a. b. EXE u u e n c o d e d c. MIME

16Perl 191 5) 6) C G I, We b U s e n e t U s e n e t 16.4 P e r l P e r l P e r l Larry Wa l l Tom Christiansen Randal Schwartz Programming Perl P e r l P e r l Tom Christiansen Nothn To r k i n g t o n The Perl Cookbook P e r l P e r l P e r l P e r l P e r l P e r l I n t e r n e t H o b b e Internet Ti m e l i n e P e r l C PA S T P e r l C PA N

192 h t t p / / w w w. Perl.com Eric S. Raymond 16.5 P e r l P e r C PA N P e r l 16.6 16.6.1 We b P e r l P e r C G I P e r l C G I P e r l C G I P e r l C G I U s e n e t C PA N h t t p :// s e a r c h. c p a n. c o m We b CPAN 16.6.2 1) P e r l C G I U s e n e t a. c o m p. i n f o s y s t e m s. w w w. a u t h o r i n g. c g i b. c o m p. l a n g. p e r l. m i s c 2) a. b. c o m p. l a n g. p e r l. m i s c c, h t t p :// w w w. Perl.com 16.6.3 1) a c o m p. l a n g. P e r l. m i s c C G I 2) a c a c w w w. P e r l. c o m

Perl C G I 1 7CGI 1 8 1 9 2 0 HTTP C G I 2 1c o o k i e 2 2 C G I 2 3 2 4 We b

1 7C G I I n t e r n e t Wold Wide We b 1993 We b I n t e r n e t 1993 I n t e r n e t 20 12 I n t r a n e t 1993 We b We We b We b We b We b We b We b C G I 7 H T M L H T M L H T M L We b H T M L We b HTML is <I>not</I> hard to learn < I > < / I > We b n o t H T M L H T M L World Wide We b W 3 C h t t p :// w w w. w3c.org HTML 24 H T M L We b C G I C G I 17.1 Web We b We b We N e t s c a p e Internet Explorer O p e r a We b We We b We b We b We We b We b We 17-1

196 Perl C G I 17-1 We b We b Web Web Web 17.1.1 Web We b U R L U R L U R L http H T T P We b f t p H T T P h t t p s w w w.google.com IP 4 2 0 9. 1 8 5. 1 0 8. 1 4 7 : 80 h t t p 80 more.html / a r c h i v e s / f o o. h t m l & h t t p 17-2 1) w w w. g o o g l e. c o m I P 2) I P w w w. g o o g l e. c o m 3) We b m o r e. h t m l 4) m o r e. h t m l 5) We b 17-2 We b Web Web Web

17CGI 197 20 17.1.2 Web CGI We b 17-3 17-3 We b Web Web Web 1 7-3 We b C G I C G I We b We b U R L C G I C G We b We 17-4 17-4 C G I We b Web Web CGI C G I We b 1) C G I 2) CGI We b 3) We b 4) CGI C G I P e r l C UNIX shell p a s c a l L I S P T C L C G I P e r l P e r l C G I C G I H T M We b C G I H T M L C G I P e r l H T M L H T T P We b C G I h t t p :// w w w. n c s a.uiuc.edu/cgi/ interface.html 7 C G I

198 Perl C G I 17.2 C G I C G C G I We b C G I We b C G I We b We b We b We b We b P e r l C G I Perl 5 C G I We b Perl 5 C G I C G I Perl 5 We b Perl CGI C G I We b We b Wi n d o w s We b P e r l C G I We b Wi n d o w s M i c r o s o f t Internet Information Server(IIS) U N I X We b U N I X We b I n t e r n e t We b A p a c h e C Apache We b A p a c h e Miorosoft Wi n d o w s A p a c h e h t t p : / / w w w. a p a c h e. o rg We b C G I We b We b We b We b C G I We b C G I C G I We b We b

17CGI 199 We b We b FA Q We b C G I We b FA Q C G I We b P e r l P e r l We b We b M i c r o s o f t We b We b C G I C G I We b We C G I C G I. c g i. p l C G I We b C G I c g i - b i n We b C G I URL We b U R L C G I http://www.myserver.com/cgi-bin/ h t t p :// w w w. m y s e r v e r. c o m / c g i / 17.3 CGI C G I C G I 17-1 h e l l o C G I C G I C G I. c g i h e l l o. c g. p l h e l l o. p 17-1 C G I 1 We b P e r l - w 2 C G I q w s t a n d a r d C G I

200 Perl C G I 3 use strict C G I 5 C G I h e a d e r C G I 6 C G I Hello world C G I 17.3.1 CGI C G I F T P C G I 1. UNIX We b t e l n e t r l o g i n UNIX We b C G I 1) F T P C G I h e l l o. c g i h e l l o. p l U N I X v i 2) m v c p C G I C G 3) U N I X h e l l o. p l C G I 2. F T P UNIX We b F T P C G I 1) F T P h e l l o. c g i h e l l o. p l C G I C G I A S C I C G I F T P 2) C G I C G h e l l o. p l h e l l o. p C G I 3) F T P C u t e - F T P Set Permissions Change Mode Set File Attributes Set File Access M o d e ( ) 755

17CGI 201 3. NT We b NT We b N T E x p l o r e r C G I C G I 4. F T P NT We b F T P NT We b F T P h e l l o. c g i hello.pl C G I C G I A S C I I C G F T P 17.3.2 CGI C G I C G I U R L C G I U R L U R C G I h e l l o. c g i C G I 1) H e l l o w o r l d We b 2) We b C G I C G I C G I C G C G I We b C G I C G I 17.4 CGI C G I C G I C G I C G I h e l l o. c g i 17.4.1 CGI C G I C G I We b C G I P e r l C G I C G I

202 Perl C G I P e r l C G I C G I 18 U N I X C t r l D C t r l D Wi n d o w s C t r l + Z P e r l C o n t e n t - Ty p e t e x t / h t m l H T M L 20 h e a d e r C o n t e n t - Ty p e C G I P e r l P e r l Ca n t locate CGI.pm in @INC...( @ I N C C G I. p m...) P e r l P e r l C G I 17.4.2 Not Found 404 Nat Found(404 ) U R L h t t p :// w w w. s e r v e r. c o m c g i - b i n / h e l l o. c g i h t t p :// w w w. s e r v e r. c o m / c g i / h e l l o. c g i C G I U R L We b C G I We b C G I. p l. c g i C G I U R L C G I U R L We b We b C G I C G I We b We b F o r b i d d e n 403 Error(403 )

17CGI 203 C G I UNIX We b h e l l o. c g i ls -1 hello.cgi F T P d i r r w x r- x r- x C G I 17.4.3 500 Internal Server Error 500 Error 5 00 C G I Internal Server Error We b We b C G I U N I X tail server_log We b C G I F T P P C I n t e r n a l Server Error No such file or directory exec of /cgi-bin/hello.cgi failed / c g i - b i n / h e l l o. c g i P e r l We b P e r l F T P l s d i r P e r l F T P C G I A S C I Wi n d o w s U N I X C G I U N I X F o r b i d d e n C a n t locate CGI.pm in @INC...(@inc C G I. p m )

204 Perl C G I P e r l P e r C G I C G I P e r l P e r l Syntax error w a r n i n g Global symbol requires e t c ( ) P e r l C G I Premature end of script headers C G I h e a d e r C o n t e n t - Ty p e h e a d e r h e a d e h e a d e r Perl CGI C o n t e n t - Ty p e t e x t / h t m l \ n \ n h e a d e r h e a d e r \ n \ n s y s t e m h e a d e r ( ` ` ) h e a d e r Perl CGI 17.5 C G I We b We C G I C G I 17.6 17.6.1 C G I

17CGI 205 C G I C G I I n t e r n e t 16 C G I 100 Perl CGI C G I C G I c g i - l i b. p l c g i - l i b. p l C G I c g i - l i b. p l P e r l C G I C T C L P e r l C G I Perl P e r l C G I P e r l C G I Perl P e r l C G I c o m p. l a n g. p e r l. m i s c c o m p. i n f o s y s t e m s. w w w. a u t h o r i n g. c g i h t t p :// w w w. w 3. o rg / C G I / FA Q 17.6.2 1) CGI a. P e r l UNIX Shell C b. C c. 2) We b P e r l a. b. 17.6.3 1) c P e r l C G I C G 2 ) b P e r l 1987 We b 1991 C E R N

206 Perl C G I 17.6.4 H e l l o w o r l d l o c a l t i m e H T M L P e r l H T M L We b We

18 We b H T M L H T M L We b We b We b S u b m i t C G I C G I Perl CGI C G I C G I 18.1 We b We b H T M L 18.1.1 HTML H T M L H T M L H T M L H T M L C G I H T M L < H E A D > < B O D Y > < D O C T Y P E > H T M L H T M L H T M L H T M L H T M We b We b C G I 18-1 H T M L 18-1 H T M L

208 Perl C G I 1 8-1 N e t s c a p e 18-1 18-1 N e t s c a p e 18-1 < F O R M > H T M L m e t h o d G E T P O S T G E C G I G E T P O S T a c t i o n C G I U R L < I N P U T > n a m e < T E X TA R E A > n a m e d e s c r i p t i o n H T M L n a m e C G I n a m e n a m e s u b m i t C G I HTML 4.0 T E X TA R E A r o w s c o l s H T M L h t t p :// w w w. w 3 c. o rg HTML 4.0 18.1.2 submit We b We b 18-2 b o d y s e x

18 209 We b 18-2 a c t i o n U R L C G I U R L 18-3 18-3 Web CGI C G I G E T P O S T C G I 18-4 18-4 Web CGI C G I 18-5 H T M L H T M L U R L H T M L C G I 18-5 We b C G I Web CGI 18.2 CGI C G I C G I p a r a m p a r a m C G I C G 18-1 p a r a m b o d y s e x n a m e s u b m i t p a r a m p a r a m ( s e x ) m a l e f e m a l e 18-2 C G I 18-2 C G I

210 Perl C G I p a r a m p a r a u n d e f GET POST 18-1 < F O R M > m e t h o d M e t h o d We b We b G E T < F O R M > G E T U R L C G I We b U R L C G I U R L p a r a m p a r a m P O S T U R L We b H T M L C G I C G I p a r a m I n t e r n e t C G I Q U E RY _ S T R I N G R E Q U E S T M E T H O D G E T P O S T C G I G E T We b We b U R L U R L C G I s a m p l e. p l C G I G E T U R L C G I C G I G E T C G I U R L P O S T U R L We b U R L P O S T C G I We b

18 211 18.3 Web C G I World Wide We b C G I We b We b H T M L We b C G I We b C G I We b 18.3.1 We b We b We H T M L 18-6 I n t e r n e t 18-6 Internet Web C G I We b 18-7 18-7 Internet Web I n t e r n e t We b We b C G I I n t e r n e t I n t e r n e t We b We b h t t p h t t p s

212 Perl C G I 18.3.2 C G I We b P e r l I n t e r n e t I n t r a n e t We b C G I 18-3 H T M L 18-4 C G I 18-3 We b 18-4 d i r e c t o r y. c g i C G I 18-3 d i r e c t o r y. c g i C G I 18-3 d i r e c t o r y. c g i D O S / w i n d o w s ls -1 d i r We b C G I $ d i r e c t o r y We b d i r n a m e / h o m e cat e t c / p a s s w d C G I We b UNIX shell M S - D O S We b I n t e r n e t P e r l - T t a i n t e d ( ) o p e n o p e n s y s t e m P e r l PAT H 18-5 18-5 directory. c g i

18 213 P e r l P e r P e r l s e c 18.3.3 H T M L C G I 18-6 H T M L 18-6 c o l o r 15 H T M L l e n g t h 15 H T M L J a v a J a v a S c r i p t c o l o r 15 P e r l 18.3.4 We b We We b We b H T M L C G I C G I C P U C G I

214 Perl C G I 18.4 We b H T M L We b 18-7 H T M L 18-7 / c g i - b i n / h e l p d e s k. c g i C G I 18-8 C G I C G I U R L 18-7 18-8 C G I

18 215 18-8 P e r l g e t _ l o c k () r e l e a s e _ l o c k () C G I C G I h e l p d e s k. c g i C G I 18-7 18.5 H T M L C G I C G p a r a m C G I C G C G I 18.6 18.6.1 17 C G I

216 Perl C G I C G I I n t e r n e t $ E N V { Q U E RY _ S T R I N G } C G I C G I P e r l - T Too late for -T option - T - T P e r l P e r l P e r l - T Perl -T -d foo.cgi P e r l C G I C G I P e r l 18.6.2 1) p a r a m a. undef b. c. 2) C G I P O S T G E T a. b. 3) HTML p a s s w o r d a. b. 18.6.3 1) c p a r a m 2) a 3) a H T T P C G I 18.6.4 d i s p l a y () d i s p l a y

1 9 We b 19.1 C G I We b We b We b We We b We We b We b We b / We b H T M L 19.2 We b We H T M L H T M H T M L H T M L f u l l n a m e Pink Floyd Perl CGI p a r a m

218 Perl C G I We b We b H T M L 1 9-1 19-1 Go to Store C G I 19-2 19-2 C G I H T M L C G I H T M L C G I 19-3 H T M L H T M L We b H T M L

19 219 We b H T T P C G I 19-3 We b View Page Source 19.3 We b We We b 4 We b We 4 We We b C G I 4 19-1 use CGI::Carp qw (fatalstobrowser), C G I d i e () We b We b C G I

220 Perl C G I C G I 19-1 6 ~ 8 H T M L s a v e r e p e a t _ h i d d e n 1 2 ~ 13 C G I p a g e _ o n e 1 4 ~ 17 p a g e o n e H T M L C G I p a g e _ t w o p a g e t w o p a g e _ t h r e e 1 9 H T M L C G I p a g e o n e p a g e t w o s u r v e y _ d o n e We b s u b m i t 19-4 s u b m i t C G I We b 19-2 19-2

19 221 19-4 0. 1 1. 2. CGI pageone CGI 3. pagetwo CGI 6. 4. CGI 5. pagethree 2 2 ~ 24 P e r l here document h e r e d o c u m e n t here document < < here document E N D _ O F _ Q U O T E 19-2 E N D _ PA G E _ O N E here document here document here document $ @ here document H T M L P e r l p r i n t 19-2 H T M L < F O R M >

222 Perl C G I < F O R M > a c t i o n C G I C G I m e t h o d G E T p a g e o n e p a g e o n C G I C G We b 19-3 C G I 19-3 4 7 46 @ s u r v e y _ a n s w e r s H T M L n a m e = 4 8 ~ 49 @ s u r v e y _ a n s w e r s H T M L <INPUT TYPE=hidden> 5 6 5 7 ~ 6 0 p a r a mp e t t y p e d o g c a t $ p e t p a r a mp e t t y p e g o l d f i s h

19 223 6 1 ~ 76 H T M L 19-4 19-4 p a g e _ t h r e e r e p e a t _ h i d d e n 19-5 C G I 19-5

224 Perl C G I 9 6 3 s a v e 1 03 s a v e 18 s a v e g e t _ l o c k r e p e a t _ h i d d e n r e l e a s e _ l o c k 19.4 We b We b 19.5 19.5.1 H T M L P e r l C G I H T M L H T M L < H E A D > < H T M L > D T D H T M L We b We b Ca n t find string terminator x x x x anywhere before EOF at... here document here here document M A R K

19 225 M S - D O S Wi n d o w s here document 19.5.2 1) We b a. c o o k i e b. H T M L c. H T M L c o o k i e 2) H T M L < F O R M > a c t i o n a. b. s u b m i t We b C G I c. s u b m i t 3) a. print<<eop 19-2 b. HTML < H E A D > c. 19.5.3 1) b c H T M L c o o k i e 2 b a c t i o n < F O R M > U R L U R 3) b p r i n t < < E O P here document c 19.5.4 C G I / - C G I / 4 0 % 4 5 % 1 5 % 2 0 % 1 5 % 30 % 3 5 % 3 5 % 4 0 %

2 0 H T T P C G I We b C G I We b H T M L C G I H T M L C G I 20.1 HTTP 17 We b N e t s c a p e Internet Explorer We b A p a c h e I I S C G I H T T P HTTP 1.0 HTTP 1.1 I n t e r n e t I n t e r n e t Request For C o m m e n t ( ) R F C R F C I n t e r n e t h t t p :// w w w. i e t f. o rg We b H T T P R F C 1 9 4 5 R F C 2 6 1 6 We b We b G E T U R L HTTP 1.0 c o n n e c t i o n We b We b k e e p - A l i v e

20 HTTP CGI 227 A c c e p t A c c e p */* i s o - 8959-1 A c c e p t - E n c o d i n g g z i p GNU Zip Ac c e p t - L a n g u a g e H o s t We b U R L We b M o z i l l a / 4. 51 [ e n ] C - c 32 f 404 p Wi n N T; U We b We b G E T We b 200 S e r v e r N e t s c a p e - Enterprise/3.51 G We b C o n t e n t - L e n g t h 2222 We b 50 % 60 % C o n t e n t - Ty p e We b H T M L t e x t / h t m l i m a g e / j p e g L a s t - M o d i f i e d We b We We b We We b We 20.1.1 Web We b We b We b Te l n e t Te l n e t U N I X H T T P U N I X Te l n e t Microsoft Wi n d o w s Te l n e t S t a r R u n Te l n e t M a c i n t o s h Te l n e t We b Te l n e t w w w. w e b s e r v e r. c o m We b 80 8 We b ) Te l n e t

228 Perl C G I Te l n e t H T T P U N I X Wi n d o w s M a c i n t o s h E n t e r We b H T T P We b 20.1.2 C G I H T M L C G I C G I h e a d e r M I M E C o n t e n t - Ty p e C o n t e n t - Ty p e h e a d e r t e x t / h t m l H T M L h e a d e r t e x t / h t m l - t y p e M I M E t e x t / p l a i n i m a g e / g i f i m a g e. j p e g G I F J P E G a p p l i c a t i o n / a p p n a m e a p p n a m e M I M E a p p l i c a t i o n / o c t e t - s t e a m We b We b We b H T M L Perl CGI We b H T M L H T M L < I M G > C G I. g i f. j p g

20 HTTP CGI 229. j p g G I F C G I d a i l y _ i m a g e. c g i 20-1 20-1 7 8 C G I H T M L $ i m a g e d i r $ e r r o r. j p g 1 0 ~ 16 Wi n d o w s S T D O U T. j p g S T D O U T b i n m o d e S T D O U T I M A G E U N I X b i n m o d e 12 1 9 H T T P C o n t e n t -Ty p e i m a g e / j p e g t e x t / h t m l 2 5 $ e r r o r d i s p l a y - i m a g e 2 6 r e a d d i r. j p g @ j p e g s

230 Perl C G I 20.2 CGI C G I C G I U R L U R L t i m e. c g i C G I t i m e. c g i We b 17 H e l l o Wo r l d C G I H T M L S u b a m i t C G I p r o c e s s. c g i C G I C G H T M L 20.2.1 CGI P e r l C G I f o o. c g i X t h i s Y t h a t <A HREF> U R L U R L 20-1 20-1 U R L CGI C G I H T M L C G I s i g n A r i e s y e a r 1969 C G I C G p a r a m

20 HTTP CGI 231 a u t h o r 20.2.2 C G I U R L U R L & I n t e r n e t RFC 2396 U R L A S C I I H e l l o, Wo r l d! U R L C G I U R L U R L H T M L CGI use CGI qw :all escape C G I e s c a p e U R L

232 Perl C G I C G I p a r a m U R L & C G I 20.3 We b We b We b We b S S I H T M L We b HTML We b We b 20-2 We b H T M L C G I 20-2 H T M L We b Web Web Web w/ssi S S I S S I H T M L H T M. s h t m l. s t m S S I Web We b H T M L H T M L Apache We b <!--#echo var= L A S T _ M O C I F I E D - - > A p a c h e We b We b

20 HTTP CGI 233 ( ) We b We b S S I We b S S I M i c r o s o f t Personal We b S S I SSI HTML Apache We b M i c r o s o f t Internet Information We b We b S S I We b S S I # e x e c SSI #exec H T M L We b # e x e c s t o c k p r i c e. c g i C G I C G I H T M L C G I # e x e c H T M L SSI We b H e l l o, Wo r l d 2 0-3 20-3 d a y. j p g n i g h t. j p g day. jpg night. jpg H T M L H T M L. s h t m l. s t m S S I

234 Perl C G I s u n m o o n. c g i 20-2 20-2 3 CGI C G I q w : a l l 6 l o c a l t i m e 4 l o c a l t i m e [ 2 ] $ h o u r # 2 24 1 5 C G I h e a d e r We b 1 6 < I M G > $ d a y $ n i g h t A LT 8 We b We b 20.4 C G I r e d i r e c t h e a d e r C G I e s c a p e p a r a m C G I 20-1 perldoc CGI C G I

20 HTTP CGI 235 We b We H T T P We b r e f e r e r u s e _ a g e n t We b s e r v e r _ n a m e 20-1 r e f e r e r u s e r _ a g e n t r e m o t e _ h o s t s c r i p t _ n a m e s e r v e r _ n a m e v i r t u a l _ h o s t We b U R L I n t e r n e t We b N e t s c a p e I E Ly n x We b I P We b U R L / c g i - b i n / f o o. c g i C G I C G I s e r v e r _ n a m e We b Vi r t u a l _ h o s t We b We b 20.5 C G I H T T P C G I We b We b We Microsoft Wi n d o w s N e t s c a p e We b

236 Perl C G I U R L C G I We b 20-4 20-4 We b We b a. Web Web X Web Y c. Web b. CGI C G I r e d i r e c t r e d i r e c t H T T P We b 20-3 Wi n d o w s N e t s c a p e We b We b 20-3 9 $ b r o w s e r 1 0 U R L $ t a rg e t N e t s c a p e 1 3 ~ 14 $ b r o w s e r M o z i l l a Wi n 1 6 C G I J a v a S c r i p t H T M L J a v a S c r i p t J a v a S c r i p t w i n d o w. l o c a t i o n. h r e f H T M L < M E TA HTTP- E Q U I V = r e f r e s h > We b J a v a S c r i p t H T T P H T M L

20 HTTP CGI 237 C G I u s e r _ a g e n t N e t s c a p e M o z i l l a We b M o s a i c Windows 95 Netscape 4.51 u s e r _ a g e n t M o z i l l a / 4. 51 Wi n 95 I 20.6 We b H T T P C G I S S HTTP 20.7 20.7.1 S S I S S I We b S S We b S S I We b S S I H T M L S S I HTML SSI <!--#exec cgi--> S S I C G We b view source S S I We b S S I Te l n e t Te l n e t We b Te l n e t 80 Te l n e t Te l n e t G E T E n t e r 20.7.2 1) U R L <A HREF=" /cgi/foo.pl? name=ben Franklin&Job=printer"> a. b. C G I c. Ben Franklin

238 Perl C G I 2) a. b. We b c. 20.7.3 1) c 2) b We b SSI HTML 20.7.4 Te l n e t We b We

2 1c o o k i e 19 H T M L We b We C G I H T T P c o o k i e HTTP Cookie H T T P C G I Co o k i e H T M L c o o k i e c o o k i e c o o k i e 21.1 cookie c o o k i e HTTP cookie C G I C G I HTML We b c o o k i e c o o k i e We b C G I c o o k i e c o o k i e 21-1 c o o k i e 21-1 c o o k i e C G I Web CGI C G I c o o k i e 21-2 2 1-2 c o o k i e Web CGI

240 Perl C G I cookie c o o k i e c o o k i e c o o k i c o o k i e c o o k i e CGI cookie 21.1.1 cookie c o o k i e C G I c o o k i e c o o k i e c o o k i e c o o k i P e r l c o o k i e c o o k i c o o k i e c o o k i e C G I h e a d e r c o o k i e - v a l u e - n a m e c o o k i e - e x p i r e s - p a t h - d o m a i n - s e c u r e C G I h e a d e r c o o k i e c o o k i e c o o k i e h e a d e r c o o k i e C G I c o o k i e C G I s a m p l e c o o k i e c o o k i e This cookie contains no MSG c o o k i e c o o k i e c o o k i e c o o k i e C G I c o o k i e c o o k i e c o o k i e c o o k i

21 cookie 241 c o o k i e C G I c o o k i e c o o k i e Sample cookie C G I c o o k i e c o o k i c o o k i e cookie sample c o o k i e c o o k i c o o k i e c o o k i N e t s c a p e A d v a n c e d P r e f e r e n c e s c o o k i e Internet Explorer Internet Options A d v a n c e d c o o k i e 21.1.2 cookie We b We b 1) 2) c o o k i e 3) We b 4) C G I 21-1 21-1 ColorChanger

242 Perl C G I 7 ~ 10 C G I p a r a mc o l o r $ r e q u e s t e d _ c o l o r 1 2 ~ 14 b g c o l o r c o o k i e $ o l d _ c o l o r c o o k i e 1 5 ~ 19 c o o k i e c o o k i e 2 0 ~ 24 c o o k i e c o o k i e 2 5 ~ 42 H T M L 30 H T M L 21.1.3 cookie 21-2 c o o k i e c o o k i e C G I We b c o o k i e c o o k i e We b

21 cookie 243 21-2 Cookie 1 0 c o o k i e c o o k i e $ c o o k i e 1 c o o k i e 11 ~ 12 c o o k i e c o o k i e c o o k i e c o o k i c o o k i e c o o k i e 21.2 cookie c o o k i e c o o k i e c o o k i e c o o k i e c o o k i e c o o k i e c o o k i e U R L 21.2.1 cookie c o o k i e c o o k i c o o k i e H T M L c o o k i e c o o k i c o o k i e c o o k i e P e r l C G I c o o k i e c o o k i e c o o k i - e x p i r e s - e x p i r e s c o o k i e 21-1 21-1 cookie + 30 s 30 + 15 m 15 + 12 h 12 + 6 M 6 + 1 Y 1 n o w c o o k i e - 10 m c o o k i e S a t u r d a y,28-aug-1999 22:51:05 GMT

244 Perl C G I 21-1 8 c o o k i e 21.2.2 cookie c o o k i e c o o k i c o o k i e c o o k i e c o o k i e c o o k i c o o k i c o o k i e c o o k i e c o o k i e c o o k i c o o k i e c o o k i e c o o k i e c o o k i e c o o k i e c o o k i e N e t s c a p e c o o k i e c o o k i e s. t x t Internet Explorer c o o k i e \ Wi n d o w s \ C o o k i e s HTTP cookie c o o k i e We b 21.2.3 cookie c o o k i e c o o k i e c o o k i We b C o n g o. c o m We b We b w w w. c o n g o. c o m s h o p p i n g. c o n g o. c o m 21-3 We b w w w. c o n g o. c o m

21 cookie 245 21-3 We b Web HTML Web www: congo.com shopping congo.con w w w. c o n g o. c o m H T M L C G I w w w. c o n g o. c o m c o o k i e w w w. c o n g o. c o m 21-4 21-4 We b c o o k i e Cookie www: congo.com www: congo.com shopping congo.con w w w. c o n g o. c o m s h o p p i n g. c o n g o. c o m c o o k i e s h o p p i n g. c o n g o. c o m HTTP cookie c o o k i w w w. c o n g o. c o m c o o k i e shopping.congo. com s h o p p i n g. c o n g o. c o m c o o k i e c o o k i c o o k i e w w w. c o n g o. c o m c o o k i e congo.com We b 21-5 21-5 We b c o o k i e Cookie www. congo.com Web Web Web www. congo.com shopping congo.com www. foo. com c o o k i e - d o m a i n c o o k i e

246 Perl C G I cookie c o o k i e c o n g o. c o m We b c o n g o. c o m c o o k i e. c o m. n e t c o o k i e. c o m. c o m 21.2.4 cookie c o o k i e c o o k i c o o k i e We b U R L CGI URL 21-6 We b 21-6 We b s a l e s C G I e n g i n e e r i n g C G I sales CGI c o o k i e engineering CGI C G I c o o k i e c o o k i e - p a t h c o o k i e U R L sales CGI c o o k i e c o o k i e - p a t h = > C G I - p a t h C G I U R L C G I s c r i p t _ n a m e C G I U R L c o o k i e c o o k i

21 cookie 247 21.2.5 cookie c o o k i e c o o k i - s e c u r c o o k i e c o o k i c o o k i e c o o k i e c o o k i e c o o k i e c o o k i We b c o o k i e c o o k i e 21.3 cookie c o o k i e c o o k i e Web CGI cookie c o o k i e c o o k i 21.3.1 cookie c o o k i e C o o k i e c o o k i e - e x p i r e c o o k i e c o o k i e 21.3.2 cookie HTTP cookie H T T P We b I n t e r n e t c o o k i e c o o k i e c o o k i N e t s c a p e 1. 1 Internet Explorer Ly n x, O p e r a We b c o o k i e c o o k i C G I u s e r _ a g e n t c o o k i e 21.3.3 cookie c o o k i e

248 Perl C G I We b We b We b I n t e r n e t c o o k i e c o o k i c o o k i e c o o k i e c o n g o. c o m We b We b We b We b c o n g o. c o m We b c o o k i e We b We b We We b We We c o o k i e c o o k i e We b c o o k i e c o o k i e We b c o o k i e c o o k i e c o o k i e c o o k i e We b We b c o o k i e HTTP cookie 21.4 HTTP cookie C G I c o o k i e We b c o o k i e c o o k i e c o o k i e 21.5 21.5.1 HTTP cookie

21 cookie 249 c o o k i e c o o k i e S p l i t c o o k i e We b 1) A HREF C G I U R L 2) r e d i r e c t. p l C G I p a r a m t a rg e t U R L h t t p :// w w w. congo.com 3) U R L c o o k i e 4) c o o k i e We b t r a c k e r c o o k i e U R L c o o k i e We b C G I r e d i r e c t h e a d e r - c o o k i e 21.5.2 1) c o o k i e a. c o o k i e b. c o o k i e

250 Perl C G I c. c o o k i e 2) c o o k i e c o o k i - e x p i r e a. +7d b. +1w c. +10080m 3) c o o k i e a. cookie b. c o o k i e c. cookie 21.5.3 1) 3 2) a c + 1 w 3) 3 21.5.4 We b I M G

21 cookie 251

2 2 C G I We b P e r l We b We b I n t e r n e t U N I X U N I X We b 22.1 Internet P e r l I n t e r n e t P e r l N C S A We b U N I X U N I X UNIX-to-UNIX copy, UUCP 22-1 22-1 UUCP UUCP UUCP Mail U U C P P C Simple Mail Transport Protocol, SMTP 22-2 Post Office Portocol, POP I n t e r n e t Internet Message Access Protocol, IMAP S M T

252 Perl C G I 22-2 SMTP SMTP SMTP SMTP POP IMAP SMTP 22.1.1 S M T P Mail Transport Agent, MTA M TA U N I X M TA s e n d m a i l s e m d m a i l U N I X f o o @ b a r. c o m s e n d m a i l Microsoft Wi n d o w s M a c i n t o s h M TA P e r l N e t :: S M T P M TA S M T P S M T P S M T P I n t e r n e t I S P S M T P We b 22.1.2 s e n d _ m a i l P e r l

253 22 CGI P e r l I n t e r n e t I S P I S P I S P a o l. c o m h o t m a i l. c o m I S P F r o m ( Reply To ) P e r l I S P I S P I S I S I n t e r n e t 22.2 P e r l C G I M TA s e n d m a i l S M T P

254 Perl C G I 22.2.1 UNIX U N I X s e n d m a i l U N I X s e n d m a i l 22-1 U N I X U N I X 22-1 send_mail 6 sendmail s e n d m a i l 8 $ s e n d m a i l s e n d m a i l M A I L 9 ~ 14 M A I L 1 5 ~ 17 M A I L \ n 4 s e n d m a i l U N I X U N I X $ s e n d m a i l s e n d m a i l / u s r / l i b / u s r / s b i n,/ l i b

255 22 CGI m a i l p i n e s e n d m a i l 21-1 s e n d m a i l -t ( F r o m To S u b j e c t ) -oi. ( ) -odq - o d q s e n d _ m a i l ( ) 22.2.2 UNIX s e n d m a i l M TA Wi n d o w s M TA P e r l P e r l N e t :: S M T P P e r l P e r l We b N e ts M T P l i b n e t L i b n e t P e r l U N I X Wi n d o w s M a c i n t o s h P e r l 22-2 M TA s e n d _ m a i l 22-2 M TA s e n d _ m a i l

256 Perl C G I 5 N e t :: S M T P 1 0 N e t :: S M T P 9 1 3 ~ 2 3 N e t : : S M T P 4 $ s m t p = N e t :: S M T P - > n e w $ r e l a y $ s m t p $ s m t p - > m a i l ( $ f r o m ) - > m a i l $ s m t p N e t :: S M T P N e t :: S M T P $smtp->mail(addr) mail $smtp->to(addr) to t B C C $smtp->data() d a t a $smtp->datasend(data) To : F r o m D a t e : R e c e i v e d : $ s m t p - > d a t a s e n d ( \ n ) $ s m t p - > d a t a s e n d () $smtp->dataend() dataend

257 22 CGI $smtp->quit() S M T P 22.3 Web s e n d _ m a i l () We b We b C G I 22-3 H T M L 22-3 H T M L C G I C G

258 Perl C G I 22-1 22 2 s e n d _ m a i l To : We b m a s t e r @ m y h o s t. c o m We b To 1 3 C G I e l s e C G I I n t e r n e t 22-1 2 2-2 I n t e r n e t R F C - 822 R F C - 822 R F C -

259 22 CGI / ^ [\ w. -] + \@([\ w, - ]\.) + \ w + $ / m e @ s o m e w h e r e. c o m R F C - 822 4700 I n t e r n e t 22.4 We b s e n d _ m a i l () P e r l I n t e r n e t 22.5 22.5.1 We b C G I r e m o t e _ h o s t We b r e m o t e _ u s e r N e t s c a p e Internet Explorer We b @( a t ) p o s t m a s t e r r o o t @ C G I From nobody s e n d m a i l I D We b We b I D n o b o b y We b h t t p d r o o t F r o m :

260 Perl C G I C PA N M I M E 22.5.2 1) $foo=net::smtp->new( m a i l h o s t ) U N I X a. b. $ f o o S M T P c. N e t :: S M T P 2) a. f o o! b a r! b a z! q u u x b. @ b a r. c o m c. s t u ff % j u n k! Wo w z e r s! f o o. c o m! b l a t 22.5.3 1) b a Perl 4 c use Net::SMTP 2) 22.5.4 C G I We b 19

2 3 C G I We b We b 23.1 We b We C G I We b C G I 90 C G I I m still working, 20%complete ( 10 ) I m still working,20% complete( 20 ) We b 23-1 23-1 We b We b We M i c r o s o f t I n t e r n et Explorer We b Internet Explorer We b

262 Perl C G I 23.1.1 We b C G I (nonparsed header)cgi C G C G I We b C G I C G 500 C G I 23-2 23-2 Web Web C G I We b Apache We b C G I n p h - p u s h. c g i C G I n p h - p u s h. c g i C G I We b M i c r o s o f t I n t e r n e t Internet Information Se r v e r, IIS C G I C G I h e a d e r I I S C G I We b 23.1.2 Web We b We b 5 We b We b We b S t o p C G I We b 23-1 H T M L We b C G I 23-1 HTML

23 263 4 C G I : p u s h C G I - n p h C G I 8 m u l t i p a r t _ i n i t We b m u l t i p a r t _ i n i t We b h e a d e r 9 w h i l e ( 1 ) w h i l e 1 0 m u l t i p a r t _ s t a r t We b We We b 11 4 l o c a l t i m e Sun Sep 5 15:15:30 1999 1 2 m u l t i p a r t _ e n d We b m u l t i p a r t _ s t a r t w h i l e m u l t i p a r t _ i n i t m u l t i p a r t _ e n d We b We b 23.1.3 23-2 / i m a g e s We b 23-2

264 Perl C G I 23-2 20 23-1 16 m u l t i p a r t _ s t a r t (- t y p e = > i m a g e / j p e g ) C G I We b H T M L J P G J P E G IMG SRC H T M L 23.1.4 We b H T M L We b U R L We b H E A D H T M L 6 We b h t t p :// f o o. b a r. c o m C G I We b We We C G I h e a d e r - R e f r e s h We b U R L c o o k i e We b We b P e r l We b Internet Explorer 23.2 We b We b 23 3 We b We b We We b We b

23 265 23-3 We b 0 1 I D We b We We b We We b We b We b A l t a Vi s t a G o o g l e H o t B o t We b We b We b R e f r e s h We b We b 17 We b 23-4 23-4 We b A Web A A

266 Perl C G I We b I S P a o l. c o m h o m e. c o m I S P I S P We b We b We b I n t e r n e t We b We b We 23-5 We b I n t e r n e t 23-5 We b Web A A We b r e m o t e _ h o s t We b We b 23.2.1 We b 20 C G I h i t s. c g i S S I We b 23-3 23-3

23 267 1 8 2 0 ~ 23 $ c o u n t e r f i l e 2 8 ~ 30 $ c o u n t e r f i l e 3 2 23-3 15 We b We 23.2.2 3 We b Perl CGI C PA N G D P e r l G D 10 0 9 1 0 I M G H T M L 23-6 23-4 Perl CGI d i g i t _ 0. j p g d i g i t _ 1. j p g d i g i t _ 9. j p g 20 C G I g r a p h i c a l _ h i t s. c g i We b

268 Perl C G I 23-4 23-6 23-4 23-4 23-3 9 $ i m a g e _ u r l U R L U R L 3 4 ~ 35 $ h i t s $ d i g i t I M G 23.3 We b

23 269 We b 23.4 23.4.1 We b C G I C G I We b 20 H T M L P O S T We b P O S T 23.4.2 1) C G I a. m u l t i p a r t _ s t a r t m u l t i p a r t _ e n d b. m u l t i p a r t _ i n i t, m u l t i p a r t _ s t a r t m u l t i p a r t _ e n d c. p u s h _ s t a r t p u s h _ e n d 2) H T M L a. b. 3) We b a. P O S T H T M L b. c. C G I 23.4.3 1) b m u l t i p a r t _ i n i t We b m u l t i p a r t _ s t a r m u l t i p a r t _ e n d We b 2) b M E TA H T M L h e a d e r - R e f r e s h We b

270 Perl C G I 3) a 23.4.4 23-3 23-4

2 4 We b We b C G I We b We We b I n t e r n e t We b 24.1 We b We b We b 24-1 24-1 We b Web Web Original Material We b C G I We b We b 24.1.1 Web

272 Perl C G I We b We b We b I S P We b We b We b We b We We b S l a s h d o t. o rg We b We b S l a s h d o t. o rg h t t p :// w w w. s l a s h d o t. o rg We b FA Q 24.1.2 We b S l a s h d o t 1) HTML We b headlines.cgi CGI 2) C G I S l a s h d o t. o rg We b 3) C G I We b We b P e r l LW P :: S i m p l e LW P I n t e r n e t We b F T P LW PS i m p l e l i b w w w - p e r l We b H T M L U R L We b L i b w w w - p e r l LW PS i m p l e We b $ c o n t e n t U R L We b 24-1 2 4-3 Sl a s h d o t 24-1 Slashdot

273 24 Web 24-2 Slashdot 24-3 Slashdot 3 ~ 6 F c n t l LW P :: S i m p l e

274 Perl C G I g e t S l a s h d o t We b C G I C G I 8 U R L s t o r y X M L P e r l 9 $ c a c h e S l a s h d o t S l a s h d o t g e t _ l o c k () r e l e a s e _ l o c k () 3 $ c a c h e 2 3 60 P e r l - M P e r l - M 1 6 - M 0.25 ( ) 1 - M 0. 0416666 ( 1 2 4 ) 2 4 U R L LW PS i m p l e g e t $ d o c g e t u n d e f 2 5 g e t _ l o c k () r e l e a s e _ l o c k () i f C G I 33 ~ 35 3 4 s t a t $ c a c h e 9 24-2 S l a s h d o t. c g i

275 24 Web l o c a l t i m e 4 0 4 3 S l a s h d o t t i t l e < u r l > U R L $ 1 $ t i t l e $ l i n k < u r l > < t i t l e > < u r l > $ t i t l e $ l i n k 45 H T M L S l a s h d o t X M L X M S l a s h d o t FA Q 24-2 H T M L 24.2 We b. t x t. t x t 24-3 24-3 C G I. t x t C G I

276 Perl C G I C G I f o o. t x t f o o. a n s w e r 24.2.1. t x t 24-4 24-4 6 $ s u r v e y _ d i r. t x t We b 755 U N I X Wi n d o w s f i n d _ l a s t _ f i l e (). t x t. a n s w e r $ s u r v e y _ d i r g e t _ f i l e _ c o n t e n t s ()

277 24 Web f i n d _ l a s t _ f i l e () u n d e f g e t _ f i l e _ c o n t e n t s (). t x t. a n s w e r f i n d _ l a s t _ f i l e () 24-5 24-5 36 g e t _ f i l e _ c o n t e n t s (). t x t $ q u e s t i o n @ a n s w e r s 40 / c g i / w r i t e s u r v e y. c g i C G I @ a n s w e r s 0 1 @ a n s w e r s a n s w e r C G I 40 / c g i / w r i t e s u r v e y. c g i 24.2.2 S u b m i t g e t _ l o c k () r e l e a s e _ l o c k () g e t _ f i l e _ c o n t e n t s () f i n d _ l a s t _ f i l e () C G I 24-6 24-6

278 Perl C G I 24-6 g e t _ f i l e _ c o n t e n t s () f i n d _ l a s t _ f i l e () g e t _ l o c k () r e l a s e _ l o c k () $ s u r v e y _ d i r We b 24-7 24-7

279 24 Web 46 $ q u e s t i o n @ p o s s _ a n s w e r s 50 S u b m i t 53 g e t _ l o c k ( ) 56. t x t f i r s t. t x t. t x t. a n s w e r f i r s t. a n s w e r r e l a s e _ l o c k () 6 6 g e t _ f i l e _ c o n t e n t s () % r e s u l t s 0 1 2 7 4 % r e s u l t s 0 76 2 4-4 C G I H T M L / w e b / h t d o c s / p o l l Windows NT G u e s t U N I X c h m o d 777 We b. a n s w e r

280 Perl C G I 24-4 24.3 We b We b We b We b 24.4 24.4.1 We b. t x t. a n s w e r c h m o d. a n s w e r 1999 2 M i c r o s o f t Ti c k e t m a s t e r M i c r o s o f t Ti c k e t m a s t e r We b Ti c k e t m a s t e r M i c r o s o f t S l a s h d o t X M L H T M H T M L H T M L

281 24 Web H T M L C PA N H T M L C PA N H T M H T M L* 24.4.2 1) We b H T M L a. LW P b. c. lynx -dump netscape -print 2) LW P :: S i m p l e g e t a. No Documcnt b. c. u n d e f 24.4.3 1) a b c 2) c 24-2 24.4.4 24-4 1 1. g i f. g i f. g i f 100 40. 4 24-4 23

P e r l P e r P e r l P e r l m o d i n s t a l l O S 2 V M S A.1 h t t p :// w w w. p e r l. c o m C PA N C PA N C PA N I m a g es i z e We b LW P P e r l l i b w w w - p e r l C PA N l i b n e t LW P l i b n e t A.2 C PA N D a t em a n i p D a t em a n i p A.2.1 Windows95 98 NT Wi n d o w s ActiveState Tool P e r l ActiveState To o l Wi n d o w s Perl Package Manager (PPM) P P M D O S A - 1 I n t e r n e t P P M P P M ActiveState Perl p p m. b a t

286 s e a r c h A c t i v e S t a t e C PA N A-1 D O S D a t e - M a n i p i n s t a l l D a t em a n i p P C I n t e r n e t A c t i v e S t a t e We b h t t p ::// w w w. A c t i v e S t a t e. c o m A c t i v e S t a t e P e r L FA Q P P M Wi n d o w s P e r l Wi n d o w s P e r l

287 A.2.2 UNIX CPAN U I N X ANSI C P e r l G N U g z i p g u n z i p U N I X h t t p :// w w w. f s f. o rg U N I X H P C ANSI C C C GNU P e r l P e r l C PA N CPAN s h e l l P e r l $ perl -MCPAN -e shell C PA N P e r l C PA N I n t e r n e t C PA N i p a t p a D a t em a n i p C PA N C PA N C PA N C PA N

288 A.2.3 UNIX C PA N U N I X CPAN C PA N D a t e :: C a l c D a t e - C a l c - X. Y. t a r. g z D a t e - C a l c - 4. 2 c d, m a k e m a k e

289 make test make test A.2.4 Macintosh M a c i n t o s h M a c P e r l FA Q MacPerl FA Q h t t p :// W W W. m a c p e r l. c o m A.3,, P e r l Wi n d o w s P P M P P s e t C :\ m y p e r l

290 U N I X CPAN m a k e p l _ a rg m a k e P R E F I X / h o m e / c l i n t p / p e r l / l i b P e r l P e r l use lib D a t e :: M a n i p h o m e / c l i n t p / p e r l / l i b A - 2 A-2 D a t e :: M a n i p P e r l