Changeset 8243 for docs/p6doc/Perl5

Show
Ignore:
Timestamp:
12/14/05 20:43:57 (3 years ago)
Author:
gaal
Message:

* docs/p6doc/ - a few small fixes to skud++'s notes

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • docs/p6doc/Perl5/Differences.pod

    r8235 r8243  
    4444    say @fruit[0]; 
    4545 
     46Or even use the C<< <> >> operator, which replaces C<qw()>: 
     47 
     48    my @fruits = <apple pear banana>; 
     49 
    4650Note that the sigil for fetching a single element has changed from C<$> 
    47 to C<@>. 
     51to C<@>; perhaps a better way to think of it is that the sigil of a 
     52variable is now a part of its name, so it never changes in subscripting. 
    4853 
    4954The same applies to hashes: 
    5055 
    5156    say "There are %days{'February'} days in February"; 
     57 
     58Again, there is a shorter form: 
     59 
     60    say "There are %days<February> days in February"; 
    5261 
    5362=head2 New ways of referring to array and hash elements 
     
    6776    Was:    $array[$#array] 
    6877    Now:    @array[@array.end] 
     78            @array[-1]              # also works 
    6979 
    7080Hash elements no longer auto-quote: 
     
    8999    Now:    <<foo>> 
    90100 
    91 =head2 Method annotation changes from -> to . 
     101=head2 Method invocation changes from -> to . 
    92102 
    93103    Was:    $object->method 
     
    100110 
    101111    Was:    my $len = length($string); 
    102     Now:    my $len = $string.length; 
     112    Now:    my $len = $string.chars; 
    103113 
    104114    Was:    print sort(@array); 
    105115    Now:    print @array.sort; 
     116            @array.sort.print; 
    106117 
    107 You can still say C<sort(@array)> but it's no longer idiomatic. 
     118You can still say C<sort(@array)> if you prefer the non-OO idiom. 
    108119 
    109120=head2 You don't need parens on control structure conditions 
     
    124135    Now:    for @whatever -> $x       { ... } 
    125136 
     137This 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 
    126144=head2 for becomes loop 
    127145 
    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++) { ... } 
    130148 
    131149=head1 AUTHOR