Changes

Jump to navigation Jump to search
1,165 bytes added ,  01:34, 30 December 2013
Line 1: Line 1:  
== NAME ==
 
== NAME ==
   −
perlintro -- a brief introduction and overview of Perl
+
perlintro -- a brief introduction and overview of Perl,if you are looking to found the complete edition of perl documentation, see http://perldoc.perl.org/index.html
    
you can find the source of this Tutorial http://perldoc.perl.org/perlintro.html
 
you can find the source of this Tutorial http://perldoc.perl.org/perlintro.html
 +
 
== DESCRIPTION ==
 
== DESCRIPTION ==
   Line 107: Line 108:  
         my $answer = 42;
 
         my $answer = 42;
   −
Scalar values can be strings, integers or floating point numbers, and Perl will automatically convert between them as required. There is no need to pre-declare your variable types, but you have to declare them using the '''my''' keyword the first time you use them. (This is one of the requirements of '''use strict;''' .)
+
Scalar values can be strings, integers or floating point numbers, and Perl will automatically convert between them as required. There is no need to pre-declare your variable types, but you have to declare them using the '''[http://perldoc.perl.org/functions/my.html my]''' keyword the first time you use them. (This is one of the requirements of '''[http://perldoc.perl.org/functions/use.html use] strict;''' .)
    
Scalar values can be used in various ways:
 
Scalar values can be used in various ways:
Line 115: Line 116:  
         print "The square of $answer is ", $answer * $answer, "\n";
 
         print "The square of $answer is ", $answer * $answer, "\n";
   −
There are a number of "magic" scalars with names that look like punctuation or line noise. These special variables are used for all kinds of purposes, and are documented in perlvar. The only one you need to know about for now is $_ which is the "default variable". It's used as the default argument to a number of functions in Perl, and it's set implicitly by certain looping constructs.
+
There are a number of "magic" scalars with names that look like punctuation or line noise. These special variables are used for all kinds of purposes, and are documented in [http://perldoc.perl.org/perlvar.html perlvar]. The only one you need to know about for now is '''$_''' which is the "default variable". It's used as the default argument to a number of functions in Perl, and it's set implicitly by certain looping constructs.
    
         print; # prints contents of $_ by default
 
         print; # prints contents of $_ by default
Line 152: Line 153:  
You can do various useful things to lists:
 
You can do various useful things to lists:
   −
         my @sorted = sort @animals;
+
         my @sorted = [http://perldoc.perl.org/functions/sort.html sort] @animals;
         my @backwards = reverse @numbers;
+
         my @backwards = [http://perldoc.perl.org/functions/reverse.html reverse] @numbers;
    
There are a couple of special arrays too, such as '''@ARGV''' (the command line arguments to your script) and '''@_''' (the arguments passed to a subroutine). These are documented in [http://perldoc.perl.org/perlvar.html perlvar].
 
There are a couple of special arrays too, such as '''@ARGV''' (the command line arguments to your script) and '''@_''' (the arguments passed to a subroutine). These are documented in [http://perldoc.perl.org/perlvar.html perlvar].
Line 173: Line 174:     
         $fruit_color{"apple"}; # gives "red"
 
         $fruit_color{"apple"}; # gives "red"
You can get at lists of keys and values with '''keys()''' and '''values()'''.
+
You can get at lists of keys and values with '''[http://perldoc.perl.org/functions/keys.html keys()]''' and '''[http://perldoc.perl.org/functions/values.html values()]'''.
    
         my @fruits = keys %fruit_colors;
 
         my @fruits = keys %fruit_colors;
Line 238: Line 239:  
==== if ====
 
==== if ====
   −
         if ( condition ) {
+
         [http://perldoc.perl.org/functions/if.html if] ( condition ) {
 
         ...
 
         ...
         } elsif ( other condition ) {
+
         } [http://perldoc.perl.org/functions/elsif.html elsif] ( other condition ) {
 
         ...
 
         ...
         } else {
+
         } [http://perldoc.perl.org/functions/else.html else] {
 
         ...
 
         ...
 
         }
 
         }
Line 248: Line 249:  
There's also a negated version of it:
 
There's also a negated version of it:
   −
         unless ( condition ) {
+
         [http://perldoc.perl.org/functions/unless.html unless] ( condition ) {
 
         ...
 
         ...
 
         }
 
         }
Line 266: Line 267:  
==== while ====
 
==== while ====
   −
         while ( condition ) {
+
         [http://perldoc.perl.org/functions/while.html while] ( condition ) {
 
         ...
 
         ...
 
         }
 
         }
Line 272: Line 273:  
There's also a negated version, for the same reason we have '''unless''' :
 
There's also a negated version, for the same reason we have '''unless''' :
   −
         until ( condition ) {
+
         [http://perldoc.perl.org/functions/until.html until] ( condition ) {
 
         ...
 
         ...
 
         }
 
         }
Line 284: Line 285:  
Exactly like C:
 
Exactly like C:
   −
         for ($i = 0; $i <= $max; $i++) {
+
         [http://perldoc.perl.org/functions/for.html for] ($i = 0; $i <= $max; $i++) {
 
         ...
 
         ...
 
         }
 
         }
   −
    The C style for loop is rarely needed in Perl since Perl provides the more friendly list scanning '''foreach''' loop.
+
The C style for loop is rarely needed in Perl since Perl provides the more friendly list scanning '''foreach''' loop.
 +
 
 
==== foreach ====
 
==== foreach ====
   −
         foreach (@array) {
+
         [http://perldoc.perl.org/functions/foreach.html foreach] (@array) {
 
         print "This element is $_\n";
 
         print "This element is $_\n";
 
         }
 
         }
Line 300: Line 302:  
         }
 
         }
   −
    The '''foreach''' keyword is actually a synonym for the for keyword. See [http://perldoc.perl.org/perlsyn.html#Foreach-Loops Foreach Loops in perlsyn].
+
The '''foreach''' keyword is actually a synonym for the for keyword. See [http://perldoc.perl.org/perlsyn.html#Foreach-Loops Foreach Loops in perlsyn].
    
For more detail on looping constructs (and some that weren't mentioned in this overview) see [http://perldoc.perl.org/perlsyn.html perlsyn].
 
For more detail on looping constructs (and some that weren't mentioned in this overview) see [http://perldoc.perl.org/perlsyn.html perlsyn].
Line 306: Line 308:  
=== Builtin operators and functions ===
 
=== Builtin operators and functions ===
   −
Perl comes with a wide selection of builtin functions. Some of the ones we've already seen include '''print''', '''sort''' and '''reverse'''. A list of them is given at the start of perlfunc and you can easily read about any given function by using '''perldoc -f functionname'''.
+
Perl comes with a wide selection of builtin functions. Some of the ones we've already seen include '''[http://perldoc.perl.org/functions/print.html print]''', '''[http://perldoc.perl.org/functions/sort.html sort]''' and '''[http://perldoc.perl.org/functions/reverse.html reverse]'''. A list of them is given at the start of [http://perldoc.perl.org/perlfunc.html perlfunc] and you can easily read about any given function by using '''perldoc -f functionname'''.
   −
Perl operators are documented in full in perlop, but here are a few of the most common ones:
+
Perl operators are documented in full in [http://perldoc.perl.org/perlop.html perlop], but here are a few of the most common ones:
    
==== Arithmetic ====
 
==== Arithmetic ====
Line 404: Line 406:  
         # in $a
 
         # in $a
   −
The '''s///''' substitution operator is documented in [http://perldoc.perl.org/perlop.html perlop].
+
The '''[http://perldoc.perl.org/functions/s.html s///]''' substitution operator is documented in [http://perldoc.perl.org/perlop.html perlop].
 +
 
 
==== More complex regular expressions ====
 
==== More complex regular expressions ====
   Line 521: Line 524:     
Kirrily "Skud" Robert <skud@cpan.org>
 
Kirrily "Skud" Robert <skud@cpan.org>
 +
[[Category:Developer]]
 +
[[Category:SME Server Development Framework]]
 +
[[Category:Development Tools]]

Navigation menu