Perl语言入门和提高04

Perl语言入门和提高04

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Spring, 2009 1 Perl 入门和提高 Lesson 4 周晓方 [email protected] Spring, 2009 2 Statement s --- perlsyn Perl 语法:查看 perlsyn 网页 复合语句,或叫块语句 { 语句 ; 语句 ; 语句 ;} Comments in Perl # This is the perl style comments. /* C style */ is not for perl, nor // C++ sytle comments Comment out block of code if (0) { some valid perl code } PoC (Plain old comments) # line 200 "bzzzt" # the previous '#' must on the first column die 'foo'; # 格式是 顶格的 '#' 可选的空格 行号 " 文件名 " foo at bzzz t line 201. Spring, 2009 3 倒装修饰的简单语句 Simple statement + modifier Simple_sta t modifier Cond ; # if/unless/while/until/foreach !!Always evaluates Condition before execute Expression !! do BLOCK while cond; run BLOCK once before evaluate cond print " \$A is negitive!" if $A < 0; die "SOS!" if ($fail); $B=1/$A unless $A == 0; ($sum, $j) = (0, 1); do { $sum += $j } while ++$j <= 100; $sum = 0; $sum += $_ foreach (1. .100) ; # loops on $_ $hash{$key} = $v unless defined($hash{$key}); # avoid over-write $I=1; $J=0; $J+=$I++ until ($I > 10); print $J; # ==> 55 per l -e "print while <>;" < readme.txt Spring, 2009 4 Control Flow 1 False conditions: 0.000, 0, undef, "0", "" (but "0.0" "00" is true) If statement: if ( ) { } # Multi-choice: # not " else if " # not " elseif " # but " elsif " if ( ) { } elsi f( ) { } elsi f( ) { } elsi f( ) { } else { } if ( ) { } else { } # compare modified statement expression if ; expression unless ; Spring, 2009 5 Control Flow 2 while loop until loop next
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/27/2011 for the course CS Perl taught by Professor Guo during the Spring '09 term at Xiamen University.

Page1 / 2

Perl语言入门和提高04

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online