2 2. 1 h e l l o h e l l o 23
2 4 2.2 2.2.1 2.2.2 d o u b l e 1 e - 1 0 0 1 e 1 0 0 i n t e g e r
2 5 1.25 2.000 3.0 7.25e45 # 7.25 10 45-6.5e24 # 6.5 10 24 # -12e-24 # 12 10-24 # -1.2E-23 # -- E 2.2.3 0 2001-40 255 61298040283768 61_298_040_283_768 2.2.4
2 6 0 x 0 b 0377 # 377 255 0xff # FF255 0b11111111 # 255 5.6 0 x F F 2 55. 000 0x1377_0b77 0x50_65_72_7C 2.2.5 2 + 3 # 2 3 5 5.1-2.4 # 5.1 2.4 2.7 3 * 12 # 3 12 = 36 14 / 2 # 14 2 7 10.2 / 0.3 # 10.2 0.3 34 10 / 3 # 3.3333333... o c t h e x ( ) b i n ( ) o c t ( ) 0 b
2 7 10 % 3 10.5 % 3.2 1 0 % 3 2 ** 3 2.3 h e l l o M a t h :: C o m p l e x
2 8 2.3.1 'fred' # fre d 'barney' # '' # ' \' ' ' : \\' 'hello\n' # hello n 'hello there' # hello there11 '\'\\' # \ n n 2.3.2 "barney" # 'barney' "hello world\n" # hello world " : \"" "coke\tsprite" # coke tabsprite
2 9 " b a r n e y " ' b a r n e y ' 0 377 2 55. 0 \ n
3 0 2.3.3. 2 + 3 2 3 "hello". "world" "hello". ' '. "world" 'hello world'. "\n" # "helloworld" # 'hello world' # "hello world\n". x "fred" x 3 # "fredfredfred" "barney" x (4+1) # "barney" x 5 "barneybarneybarneybarneybarney" 5 x 4 # "5" x 4 "5555" 5 " 5 " 5 555 4 x 5 4 4 4444
3 1 2.3.4 +. "12" * "3" 3 6 "12fred34" * "3" 3 6 Z "Z". 5 * 7 # "Z". 35 "Z35" h e x ( ) o c t ( )
3 2 2.4 Perl - w $ perl -w my_program #! #!/usr/bin/perl -w #! #!perl -w ' 1 2 f r e d 3 4 ' Argument "12fred34" isn't numeric - w 2.5
3 3 $ $ F r e d $ f r e d $a_very_long_variable_that_ends_in_1 $a_very_long_variable_that_ends_in_2 $ $ $ $ 2.5.1 $ r $ l i n e _ l e n g t h $ n $ s u p e r _ b o w l $ s u p e r b o w l $ s u p e r b _ o w l $ s t o p i d $ s t o _ p i d$ s t o p _ i d $ A R G V $ u n d e r s c o r e s _ a r e _ c o o l $ g i v e M e I n i t i a l C a p s
3 4 $ O O O 0 0 0 O O O$ O O 0 0 O O 0 0 $ O 0 O 0 O 0 O 0 O 2.5.2 $fred = 17; $barney = 'hello'; $barney = $fred + 3; $barney = $barney * 2; # $fred 17 # $barney 'hello' # $barney $fred 3 20 # $barney $barney 2 40 $ b a r n e y 2.5.3 $fred = $fred + 5 $bar ney = - $ f r e d ;? :
3 5 $fred = $fred + 5; $fred += 5; # # $barney = $barney * 3; $barney *= 3; str = $str. " "; $str.= " "; # $str # * * = $fred **= 3 $ f r e d $ f r e d 2.6 print p r i n t () print "hello worldj\n"; # hello world print "The answer is "; print 6 * 7; print ".\n"; p r i n t print "The answer is ", 6 * 7, ".\n";
3 6 2.6.1 $meal = "brontosaurus steak"; $barney = "fred ate a $meal"; # $barney "fred ate a brontosaurus steak" $barney = 'fred ate a '. $meal; # $barney = "fred ate a $meal"; # $barney "fred ate a " print "$fred"; # print $fred; # $ $ $ u n d e f
3 7 $fred = 'hello'; print "The name is \$fred.\n"; print 'The name is $fred'. "\n"; # $ # $what = "brontosaurus steak"; $n = 3; print "fred ate $n $whats.\n"; print "fred ate $n ${what}s.\n"; print "fred ate $n $what". "s.\n"; print 'fred ate '. $n. ' '. $what. "s.\n"; # steaks$whats # # $what # # 2.6.2 2 + 3 * 4 5 * 4 20 2 + 12 1 4 ( 2 + 3 )* 42 02 + ( 3 * 4 )
3 8
3 9 4 ** 3 ** 2 # 4 ** (3 ** 2) 4 ** 9 72 / 12 / 3 # (72 / 12) / 36/3 2 36 / 6 * 3 # (36/6)*3 18 * * * / 2.6.3 < <= == >= >!=
4 0 l t le eq ge gt ne 35!= 30 + 5 # 35 == 35.0 # '35' eq '35.0' # 'fred' lt 'barney' # 'fred' lt 'free' # 'fred' eq "fred" # 'fred' eq 'Fred' # ' ' gt '' # 2.7 if i f
4 1 if ($name gt 'fred') { print "'$name' 'fred'.\n"; } e l s e if ($name gt 'fred') { print "'$name' 'fred' \n"; } else { print "'$name' 'fred' \n"; print " \n"; } 2.7.1 i f $is_bigger = $name gt 'fred'; if ($is_bigger) {... } u n d e f ' 0 ' u n d e f0' ' ' 0 '
4 2! if (! $is_bigger) { # $is_bigger } 2.8 < S T D I N > < S T D I N > $line = <STDIN>; if ($line eq "\n") { print "!\n"; } else { print " $line"; } S T D I N T e r m :: R e a d l i n e
4 3 c h o m p 2.9 chomp c h o m p c h o m p $text = " \n"; chomp($text); # <STDIN> # c h o m p c h o m p chomp($text = <STDIN>); $text = <STDIN>; chomp($text); # #... #... c h o m p c h o m p c h o m p $food = <STDIN>; $betty = chomp $food; # 1 -- c h o m p
4 4 c h o m p c h o m p c h o p c h o m p p e b b l e s p e b b l e 2.10 while w h i l e $count = 0; while ($count <= 10) { $count += 1; print " $count\n"; # 1 10 } i f i f 2.11 undef u n d e f $ / r e a d
4 5 u n d e f # $n = 1; while ($n < 10) { $sum += $n; $n += 2; # } print "$sum\n"; $ s u m u n d e f $ n $ s u m u n d e f $ s u m $string.= " \n"; $ s t r i n g u n d e f " \ n " u n d e f u n d e f p r i n t
4 6 2.12 defined < S T D I N > u n d e f u n d e f u n d e f d e f i n e d u n d e f $madonna = <STDIN>; if ( defined($madonna) ) { print " $madonna"; } else { print "!\n"; } u n d e f u n d e f $madonna = undef; # 2.13
4 7 x
4 8