Changeset 12677 for docs/Perl6/Perl5

Show
Ignore:
Timestamp:
08/25/06 03:30:22 (2 years ago)
Author:
markstos
Message:

Re-organize Differences.pod to follow the same pattern that the Synopsis,
Apocalypse and Exegesis do. Also, some more content and links were added.

Files:
1 modified

Legend:

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

    r12637 r12677  
    1 =begin maintainer_notes 
    2  
    3 Since I *am* a Perl 5 programmer coming to Perl 6 for the first time, it 
    4 seems appropriate to make notes on what I needed to get used to in Perl 
    5 6.  I'm going to start out more or less making a running list of items, 
    6 and then I guess they can be organised more neatly later on.  -- KR 
    7  
    8 =end maintainer_notes 
    9  
    101=head1 NAME 
    112 
    12 Perl6::Perl5::Differences -- differences between Perl 5 and Perl 6 
     3Perl6::Perl5::Differences -- Differences between Perl 5 and Perl 6 
    134 
    145=head1 DESCRIPTION 
    156 
    16 This document is intended to be used by Perl 5 programmers who are new 
    17 to Perl 6 and just want a quick overview of the main differences.  More 
    18 detail on everything can be found in the language reference. 
    19  
    20 The ordering of this document is more or less in order from basic stuff 
    21 to complex stuff.  To put it another way, it's been written in the order 
    22 that the topics came up while the author was learning Perl 6. 
    23  
    24 =head2 say() 
    25  
    26 This is a version of print() that auto-appends a newline: 
    27  
    28     Was:    print "Hello, world!\n"; 
    29     Now:    say   "Hello, world!"; 
    30  
    31 Since you want to do that so often anyway, it seemed like a handy thing 
    32 to make part of the language. 
     7This document is intended to be used by Perl 5 programmers who are new to Perl 
     86 and just want a quick overview of the main differences.  More detail on 
     9everything can be found in the language reference, which have been linked to 
     10throughout.  
     11 
     12This list is currently known to be incomplete. 
     13 
     14=cut  
     15 
     16# S02 
     17 
     18=head1 Bits and Pieces 
    3319 
    3420=head2 Sigils 
     
    6046    say "There are %days<February> days in February"; 
    6147 
     48For details, see L<S02/"Names and Variables">. 
     49 
     50=head2 Global Variables have a twigil 
     51 
     52Yes, a twigil. It's the second character in the variable name. For globals, 
     53it's a C<*> 
     54 
     55    Was:    $ENV{FOO} 
     56    Now:    %ENV<FOO> 
     57 
     58For details, see L<S02/"Names and Variables">. 
     59 
    6260=head2 New ways of referring to array and hash elements 
    6361 
     
    7876            @array[-1]              # also works 
    7977 
    80 Hash elements no longer auto-quote: 
    81  
    82     Was:    $days{February} 
    83     Now:    %days{'February'} 
    84     Or:     %days{"February"} 
    85     Or:     %days<February> 
    86     Or:     %days<<February>> 
    87  
    88 The curly-bracket forms still work, but curly-brackets are more 
    89 distinctly block-related now, so in fact what you've got there is a 
    90 block that returns the value "February".  The C<<>> and C<<<>>> forms 
    91 are in fact just quoting mechanisms (see below). 
     78For details, see L<S02/"Built-In Data Types"> 
     79 
     80=cut  
     81 
     82# S03 
     83 
     84=head1 Operators 
     85 
     86A comprehensive list of operator changes are documented here: 
     87 
     88L<S03/"Changes to Perl 5 operators"> 
     89L<S03/"New operators"> 
     90 
     91Some highlights: 
    9292 
    9393=head2 q(), qq(), etc have changed 
     
    9999    Now:    <<foo>> 
    100100 
    101 =head2 Method invocation changes from -> to . 
    102  
    103     Was:    $object->method 
    104     Now:    $object.method 
    105  
    106 =head2 Built-in functions are now methods 
    107  
    108 Most (all?) built-in functions are now methods of built-in classes such 
    109 as String, Array, etc. 
    110  
    111     Was:    my $len = length($string); 
    112     Now:    my $len = $string.chars; 
    113  
    114     Was:    print sort(@array); 
    115     Now:    print @array.sort; 
    116             @array.sort.print; 
    117  
    118 You can still say C<sort(@array)> if you prefer the non-OO idiom. 
     101=cut 
     102 
     103# S04 
     104 
     105=head1 Blocks and Statements 
     106 
     107See L<S04> for the full specification of blocks and statements in Perl6. 
    119108 
    120109=head2 You don't need parens on control structure conditions 
     
    125114Likewise for C<while>, C<for>, etc. 
    126115 
    127 =head2 foreach becomes for 
    128  
    129     Was:    foreach (@whatever) { ... } 
    130     Now:    for @whatever       { ... } 
    131  
    132 Also, the way of assigning to something other than C<$_> has changed: 
    133  
    134     Was:    foreach my $x (@whatever) { ... } 
    135     Now:    for @whatever -> $x       { ... } 
    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  
    144 =head2 for becomes loop 
    145  
    146     Was:    for  ($i=0; $i<10; $i++) { ... } 
    147     Now:    loop ($i=0; $i<10; $i++) { ... } 
    148  
    149 =head2 Global Variables have a twigil 
    150  
    151 Yes, a twigil. It's the second character in the variable name. For globals, 
    152 it's a C<*> 
    153  
    154     Was:    $ENV{FOO} 
    155     Now:    %ENV<FOO> 
    156  
    157 For details, see L<S02/"Names and Variables">. 
    158  
    159 =head2 eval {} is now  try {} 
     116=head2 eval {} is now try {} 
    160117 
    161118Using C<eval> on a block is now replaced with C<try>. 
     
    175132See L<S04/"Exception_handlers"> for details. 
    176133 
    177 =head1 SEE ALSO 
    178  
    179 =over 
    180  
    181 =item  L<S03/"Changes to Perl 5 operators"> 
    182  
    183 =back  
     134=head2 foreach becomes for 
     135 
     136    Was:    foreach (@whatever) { ... } 
     137    Now:    for @whatever       { ... } 
     138 
     139Also, the way of assigning to something other than C<$_> has changed: 
     140 
     141    Was:    foreach my $x (@whatever) { ... } 
     142    Now:    for @whatever -> $x       { ... } 
     143 
     144This can be extended to take more than one element at a time: 
     145 
     146    Was:    while (my($age, $sex, $location) = splice @whatever, 0, 3) { ... } 
     147    Now:    for @whatever -> $age, $sex, $location { ... } 
     148 
     149(Only the C<for> version does not destroy the array.) 
     150 
     151See L<S04/"The for statement"> for details.  
     152 
     153=head2 for becomes loop 
     154 
     155    Was:    for  ($i=0; $i<10; $i++) { ... } 
     156    Now:    loop ($i=0; $i<10; $i++) { ... } 
     157 
     158=cut 
     159 
     160# S05 
     161 
     162=head1 Regexes and Rules  
     163 
     164=cut 
     165 
     166# S06 
     167 
     168=head1 Subroutines 
     169 
     170=cut  
     171 
     172# S07 
     173 
     174=head1 Formats 
     175 
     176=cut  
     177 
     178=head2 Formats have been replaced with forms.  
     179 
     180For details see :  
     181 
     182L<http://dev.perl.org/perl6/doc/design/apo/A07.html> Format Apocalypse 
     183 
     184L<http://dev.perl.org/perl6/doc/design/exe/E07.html> Format Exegesis 
     185 
     186=cut  
     187 
     188#S10  
     189 
     190=head1 Packages 
     191 
     192=cut  
     193 
     194#S11  
     195 
     196=head1 Modules 
     197 
     198=cut  
     199 
     200#S12 
     201 
     202=head1 Objects 
     203 
     204=head2 Method invocation changes from -> to . 
     205 
     206    Was:    $object->method 
     207    Now:    $object.method 
     208 
     209#S13 
     210 
     211=cut  
     212 
     213=head1 Overloading 
     214 
     215=cut  
     216 
     217#S29 
     218 
     219=head1 Builtin Functions 
     220 
     221A number of builtin's have been removed. For details, see: 
     222 
     223L<S29/"Obsolete"> 
     224 
     225=begin TODO 
     226 
     227The new syntax didn't test out to work. Waiting on confirmation 
     228of correct examples.  
     229 
     230#=head2 ref is gone 
     231 
     232  Was: ref $foo eq 'HASH' 
     233  Now: $foo ~~ 'Hash' 
     234 
     235  Was: ref $foo eq 'ARRAY' 
     236  Now: $foo ~~ 'Array' 
     237 
     238  Was: ref $foo eq 'CODE' 
     239  Now: $foo ~~ 'Code' 
     240 
     241The "obsolete" reference above has the details.  
     242 
     243=end TODO 
     244 
     245=head2 say() 
     246 
     247This is a version of print() that auto-appends a newline: 
     248 
     249    Was:    print "Hello, world!\n"; 
     250    Now:    say   "Hello, world!"; 
     251 
     252Since you want to do that so often anyway, it seemed like a handy thing 
     253to make part of the language. 
     254 
     255=head1 Unfiled 
     256 
     257=head2 Hash elements no longer auto-quote 
     258 
     259Hash elements no longer auto-quote: 
     260 
     261    Was:    $days{February} 
     262    Now:    %days{'February'} 
     263    Or:     %days{"February"} 
     264    Or:     %days<February> 
     265    Or:     %days<<February>> 
     266 
     267The curly-bracket forms still work, but curly-brackets are more 
     268distinctly block-related now, so in fact what you've got there is a 
     269block that returns the value "February".  The C<<>> and C<<<>>> forms 
     270are in fact just quoting mechanisms (see below). 
     271 
     272=head2 Built-in functions are now methods 
     273 
     274Most (all?) built-in functions are now methods of built-in classes such 
     275as String, Array, etc. 
     276 
     277    Was:    my $len = length($string); 
     278    Now:    my $len = $string.chars; 
     279 
     280    Was:    print sort(@array); 
     281    Now:    print @array.sort; 
     282            @array.sort.print; 
     283 
     284You can still say C<sort(@array)> if you prefer the non-OO idiom. 
    184285 
    185286=head1 AUTHORS 
    186287 
    187 Kirrily "Skud" Robert, <skud@cpan.org> 
     288Kirrily "Skud" Robert, <skud@cpan.org>, 
     289Mark Stosberg