1. Trang chủ
  2. » Công Nghệ Thông Tin

Perl coures english slide

64 362 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 64
Dung lượng 536,5 KB

Nội dung

Perl course       ! !!"##$ %&&% Books The beginner book Learning Perl'(  )*+!, )/ The bible Programming Perl'0 1'!+2-, )/ !34 Links 5 66  6 ! 66  6 !6 66  6 - 66  6636 Perl strengths and weaknesses )- 738 )98'5! 8 1 :;! <== -> >! ,/!! Variables ;,/?  ; ! !  !    !  ! ;       @  !'A    !  A ; ,!! /' ?3! B8!?;"'?'?5'?!!C Numbers and operators >!==!D $num = 1; $num = 324.657; $num = -0.043; ! E3F6FFG  H,/+,/I,8/J,/KK,/LL ,/ !! EE33 Strings  $string = ’This is a literal string’; $string = ”This is an $interpolated string\n”; M     ;    !   !'  N   N M! 8  ;;  .,/x,/ Conditional statement ! if ( predicate ) { # this will be executed if the predicate is true } !8;! if ( predicate ) { # this will be executed if the predicate is true } elsif ( predicate2 ) { # no spelling mistake # this will be executed if this predicate is true } else { # finally this is excuted if no predicates where true }  unless ( predicate ) { # this will be executed if the predicate is false } Predicates !8 ;!!8 >!! < > <= >= == != <=> ! lt gt le ge eq ne cmp  && and || or ! not xor B8! $age > 18 and $height < 1.4 ($name eq ’Peter’ or $name eq ’Chris’) and $wage <= 25000 3,*/; Loops - while  # some initialization while ( predicate ) { # code which is executed while the predicate is true } ;! until ( predicate ) { # code which is executed while the predicate is false } do { # code } while ( predicate ); [...]... too if (defined $line) {} A simple Perl program #!/usr/bin /perl –w print ”Hello user !\nWhat is your name: ”; $name = ; chomp $name; if ($name eq ’Peter’) { print ”Ahh, welcome back, sensei\n”; } else { print ”Good of you to come, $name\n”; } Strict Perl Perl is a rather loose and forgiving language This can be improved somewhat by using strict #!/usr/bin /perl –w use strict; This will enforce... keyboard like any lines are read from a filehandle $line = ; Perl is mostly used in applications where linebased I/O makes sense, even though Perl can do other types of I/O When reading a line, it is important to realize that a line ends with a newline, which is part of what is read You have to get rid of that newline so often that Perl has a function for that: chomp $line; If there is no input... in $filename is piped (read) to Perl open(IN, ’ 80; $x = 0 unless $x > 0; print ”$i\n” for ($i = 1; $i . %&&% Books The beginner book Learning Perl& apos;(  )*+!, )/ The bible Programming Perl& apos;0 1'!+2-,. value. ' if (defined $line) {} A simple Perl program #!/usr/bin /perl –w print ”Hello user ! What is your name: ”; $name = <STDIN>; chomp $name; if. of you to come, $name ”; } Strict Perl       ;      !;! #!/usr/bin /perl –w use strict;   

Ngày đăng: 23/10/2014, 16:11

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN