Changeset 8243 for docs/p6doc/Perl5
- Timestamp:
- 12/14/05 20:43:57 (3 years ago)
- Files:
-
- 1 modified
-
docs/p6doc/Perl5/Differences.pod (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/p6doc/Perl5/Differences.pod
r8235 r8243 44 44 say @fruit[0]; 45 45 46 Or even use the C<< <> >> operator, which replaces C<qw()>: 47 48 my @fruits = <apple pear banana>; 49 46 50 Note that the sigil for fetching a single element has changed from C<$> 47 to C<@>. 51 to C<@>; perhaps a better way to think of it is that the sigil of a 52 variable is now a part of its name, so it never changes in subscripting. 48 53 49 54 The same applies to hashes: 50 55 51 56 say "There are %days{'February'} days in February"; 57 58 Again, there is a shorter form: 59 60 say "There are %days<February> days in February"; 52 61 53 62 =head2 New ways of referring to array and hash elements … … 67 76 Was: $array[$#array] 68 77 Now: @array[@array.end] 78 @array[-1] # also works 69 79 70 80 Hash elements no longer auto-quote: … … 89 99 Now: <<foo>> 90 100 91 =head2 Method annotation changes from -> to .101 =head2 Method invocation changes from -> to . 92 102 93 103 Was: $object->method … … 100 110 101 111 Was: my $len = length($string); 102 Now: my $len = $string. length;112 Now: my $len = $string.chars; 103 113 104 114 Was: print sort(@array); 105 115 Now: print @array.sort; 116 @array.sort.print; 106 117 107 You can still say C<sort(@array)> but it's no longer idiomatic.118 You can still say C<sort(@array)> if you prefer the non-OO idiom. 108 119 109 120 =head2 You don't need parens on control structure conditions … … 124 135 Now: for @whatever -> $x { ... } 125 136 137 This can be extended to take more than one element at a time: 138 139 Was: while (my($age, $sex, $location) = splice @whatever, 0, 3) { ... } 140 Now: for @whatever -> $age, $sex, $location { ... } 141 142 (Only the C<for> version does not destroy the array.) 143 126 144 =head2 for becomes loop 127 145 128 Was: for ($i=0; $i<10;$i++) { ... }129 Now: loop ($i=0; $i<10;$i++) { ... }146 Was: for ($i=0; $i<10; $i++) { ... } 147 Now: loop ($i=0; $i<10; $i++) { ... } 130 148 131 149 =head1 AUTHOR
