Txt die if a 4 and b 6 die if not open

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

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

Unformatted text preview: 看perl关于运算符的文档 Sometimes use with "pod2text", "pod2html" 2 • 逐渐习惯Perl的写法 – if (($a > 4) && ($b > 6)) {…;} – if (not open F, "a.txt") { die; } if ($a > 4 and $b > 6) {…;} die if not open $, "a.txt"; open F, "a.txt" or die; $a >= 0 or $a = -$a; – if ($a < 0) { $a = -$a;} 6 Context上下文: scalar, list @junk print print $size $size Spring, 2010 Precedence (cont.) • 逻辑运算和逻辑位操作的优先级比 关系运算的优先级低 Spring, 2010 = (1, "I", undef, 66..69, "foo"); @junk; #array context 1I66676869foo @junk . "\n"; #scalar context 8 = @junk; #scalar context $size is 8 = scalar @junk; $size is 8 #scalar() force a scalar context s calar returns number of elements scalar @array s calar returns its final element scalar (LIST) These are scalar context print @junk . “\n”; print @junk + 0; $size = @junk; These are list context print @junk, “\n”; ($head) = @junk; Function behaviors differently to context $line = <FILE>; @lines = <FILE>; – 判断$a最低位是否是0应该用($a & 0x1) == 0 • $a & 0x0001 == 0 相当于 $a & (0x0001 == 0) – 计算$a或$b,结果存入$c • $c = $a || $b; # correct • $c = $a or $b; # wrong • 在易混淆之处,宜加上括号,也有助于 阅读 3 7 Operators, See also "perlo...
View Full Document

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

Ask a homework question - tutors are online