- Timestamp:
- 09/20/08 22:53:26 (4 months ago)
- Location:
- docs/tutorial
- Files:
-
- 3 modified
-
ch01_overview.pod (modified) (1 diff)
-
ch04_basic_syntax.pod (modified) (2 diffs)
-
ch05_subroutines.pod (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/tutorial/ch01_overview.pod
r16690 r22301 85 85 the job. A linguist at heart, Larry set out to create his own 86 86 programming language, which he called I<perl>. He released the first 87 version of Perl on December 18, 1987 . Hemade it freely available on88 Usenet (this was before the Internet took over the world, remember) ,89 and quickly a community of Perl programmers grew.87 version of Perl on December 18, 1987 and made it freely available on 88 Usenet (this was before the Internet took over the world, remember). 89 Before long, a small community of Perl programmers grew up around it. 90 90 91 91 The early adopters of Perl were system administrators who had hit the -
docs/tutorial/ch04_basic_syntax.pod
r17701 r22301 88 88 89 89 @crew = "Zaphod", "Ford", "Trillian"; 90 90 91 91 $second_member = @crew[1]; # Ford 92 92 … … 142 142 143 143 As with arrays, assignment to a hash parses everything after the C<=> 144 as a list, so parentheses are not needed around the list. 144 as a list, so parentheses are not needed around the list N<Although 145 you can have them too, if you prefer>. 145 146 146 147 The key for each value may be a string or an object, though there are -
docs/tutorial/ch05_subroutines.pod
r16696 r22301 8 8 9 9 X<subroutines> 10 Subroutines are reusable units of code. They can be called from just 11 about anywhere, and return control to the point of the call when they 12 finish executing. They can be passed zero or more argumentsN<Following 13 the example set in Apocalypse 6, throughout this chapter we'll use the 14 term "argument" for the values passed into a subroutine call and 15 "parameter" for the lexical variables declared in the subroutine's 16 signature.> and return zero or more results. Subroutines can be named 17 or anonymous. They can be lexically scoped, package scoped, or 18 globally scoped. "Multi" subs allow multiple subroutines to have the 19 same name as long as they have different parameter lists. 20 21 Methods have a few significant differences from subroutines. In Perl 6 22 they're even distinguished by a separate keyword, C<method>. Because 23 of these differences, they'll be discussed in A<CHP-6>Chapter 6. 10 Subroutines are reusable units of code, and one of the fundamental 11 building blocks of modern programming languages. They can be called 12 from just about anywhere, and return control to the point of the call 13 when they finish executing. They can be passed zero or more 14 argumentsN<Throughout this chapter we'll use the term "argument" for 15 the values passed into a subroutine call and "parameter" for the 16 lexical variables declared in the subroutine's signature.> and return 17 zero or more results. Some programmers may be more familar with 18 languages which only allow a single return value from a subroutine, 19 or languages for which subroutines have exactly zero return values and 20 "functions" may have one. Perl 6 generalized the concept to allow 21 subroutines to return as many, or as few, return values as needed. We 22 think it just makes more sense to let the programmer do what they want 23 to do in this regard. 24 25 Subroutines can be named or anonymous. They can be lexically scoped, 26 package scoped, or globally scoped. Subroutines can be "Multi" subs, 27 which allow multiple subroutines to have the same name as long as 28 they have different parameter lists. 29 30 Blocks of reusable code can also be called the "methods" of a particular 31 class of object. Methods have a few significant differences from 32 subroutines, a few significant differences from those found in Perl 5. 33 For instance, in Perl 6 they're distinguished by a separate keyword, 34 C<method>. Because of these differences, they'll be discussed in 35 A<CHP-6>Chapter 6. 24 36 25 37 =head1 Using Subroutines … … 37 49 38 50 The simplest subroutine call is just the subroutine name followed by a 39 comma-separated list of variables or values: 51 comma-separated list of variables or values: 40 52 41 53 $result = sum($a, $b, 42, 57); … … 48 60 predeclared, but required for all other calls. Including the C<&> 49 61 sigil before the subroutine name in a call will not turn off signature 50 checking . In fact, in most contexts prefixing the subroutine name with51 C<&> will return a reference to the subroutine instead of callingthe52 subroutine .62 checking as it did in Perl 5. In fact, in most contexts prefixing 63 the subroutine name with C<&> will return a reference to the 64 subroutine instead of actually calling the subroutine. 53 65 54 66 =head1 Parameters … … 56 68 Z<CHP-5-SECT-2> 57 69 58 X<parameters;formal> 70 X<parameters;formal> 59 71 X<formal parameters> 60 72 X<subroutines;signatures> 61 X<subroutines;parameters> 73 X<subroutines;parameters> 62 74 One of the most significant additions to subroutines in Perl 6 is 63 75 named formal parameters. The parameter list, often called the … … 108 120 ... 109 121 } 110 122 111 123 whole(@array, %hash); 112 124
