Lesson4 - Spring, 2009 while loop next redo last Control...

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 周晓方 courses@xfzhou.homeftp.org Spring, 2009 2 Statements --- 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 bzzzt line 201. Spring, 2009 3 倒装修饰的简单语句 • Simple statement + modifier Simple_stat 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 perl -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 ( ) { } elsif ( ) { } elsif ( ) { } elsif ( ) { } else { } if ( ) { } else { } # compare modified statement expression if ; expression unless ; Spring, 2009 5 Control Flow 2 while loop until loop – next b jump to continue block and check condition – redo b jump to beginning of loop, no continue block or cond check
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.

Page1 / 2

Lesson4 - Spring, 2009 while loop next redo last Control...

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