This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don't use /dev/tty if it happens to exist on Windows
[perl5.git] / pod / perlintro.pod
index da9c2af..afce360 100644 (file)
@@ -22,6 +22,25 @@ Throughout this document you'll see references to other parts of the
 Perl documentation.  You can read that documentation using the C<perldoc>
 command or whatever method you're using to read this document.
 
+Throughout Perl's documentation, you'll find numerous examples intended
+to help explain the discussed features.  Please keep in mind that many
+of them are code fragments rather than complete programs.
+
+These examples often reflect the style and preference of the author of
+that piece of the documentation, and may be briefer than a corresponding
+line of code in a real program.  Except where otherwise noted, you
+should assume that C<use strict> and C<use warnings> statements
+appear earlier in the "program", and that any variables used have
+already been declared, even if those declarations have been omitted
+to make the example easier to read.
+
+Do note that the examples have been written by many different authors over
+a period of several decades.  Styles and techniques will therefore differ,
+although some effort has been made to not vary styles too widely in the
+same sections.  Do not consider one style to be better than others - "There's
+More Than One Way To Do It" is one of Perl's mottos.  After all, in your
+journey as a programmer, you are likely to encounter different styles.
+
 =head2 What is Perl?
 
 Perl is a general-purpose programming language originally developed for
@@ -54,22 +73,28 @@ Alternatively, put this as the first line of your script:
 ... and run the script as C</path/to/script.pl>.  Of course, it'll need
 to be executable first, so C<chmod 755 script.pl> (under Unix).
 
+(This start line assumes you have the B<env> program.  You can also put
+directly the path to your perl executable, like in C<#!/usr/bin/perl>).
+
 For more information, including instructions for other platforms such as
 Windows and Mac OS, read L<perlrun>.
 
 =head2 Safety net
 
-Perl by default is very forgiving. In order to make it more roboust
-it is recommened to start every program with the following lines:
+Perl by default is very forgiving.  In order to make it more robust
+it is recommended to start every program with the following lines:
 
     #!/usr/bin/perl
     use strict;
     use warnings;
 
-The C<use strict;> line imposes some restrictions that will mainly stop
-you from introducing bugs in your code.  The C<use warnings;> is more or
-less equivalent to the command line switch B<-w> (see L<perlrun>). This will
-catch various problems in your code and give warnings.
+The two additional lines request from perl to catch various common
+problems in your code.  They check different things so you need both.  A
+potential problem caught by C<use strict;> will cause your code to stop
+immediately when it is encountered, while C<use warnings;> will merely
+give a warning (like the command-line switch B<-w>) and let your code run.
+To read more about them check their respective manual pages at L<strict>
+and L<warnings>.
 
 =head2 Basic syntax overview
 
@@ -138,7 +163,7 @@ A scalar represents a single value:
 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 C<my> keyword the first time you use them. (This is one of the
+the C<my> keyword the first time you use them.  (This is one of the
 requirements of C<use strict;>.)
 
 Scalar values can be used in various ways:
@@ -182,7 +207,7 @@ of elements in the array:
     if (@animals < 5) { ... }
 
 The elements we're getting from the array start with a C<$> because
-we're getting just a single value out of the array -- you ask for a scalar,
+we're getting just a single value out of the array; you ask for a scalar,
 you get a scalar.
 
 To get multiple values from an array:
@@ -242,9 +267,9 @@ More complex data types can be constructed using references, which allow
 you to build lists and hashes within lists and hashes.
 
 A reference is a scalar value and can refer to any other Perl data
-type. So by storing a reference as the value of an array or hash
+type.  So by storing a reference as the value of an array or hash
 element, you can easily create lists and hashes within lists and
-hashes. The following example shows a 2 level hash of hash
+hashes.  The following example shows a 2 level hash of hash
 structure using anonymous hash references.
 
     my $variables = {
@@ -296,15 +321,14 @@ are defined.
 Using C<my> in combination with a C<use strict;> at the top of
 your Perl scripts means that the interpreter will pick up certain common
 programming errors.  For instance, in the example above, the final
-C<print $b> would cause a compile-time error and prevent you from
+C<print $y> would cause a compile-time error and prevent you from
 running the program.  Using C<strict> is highly recommended.
 
 =head2 Conditional and looping constructs
 
-Perl has most of the usual conditional and looping constructs except for
-case/switch (but if you really want it, there is a Switch module in Perl
-5.8 and newer, and on CPAN. See the section on modules, below, for more
-information about modules and CPAN).
+Perl has most of the usual conditional and looping constructs.  As of Perl
+5.10, it even has a case/switch statement (spelled C<given>/C<when>).  See
+L<perlsyn/"Switch Statements"> for more details.
 
 The conditions can be any Perl expression.  See the list of operators in
 the next section for information on comparison and boolean logic operators,
@@ -363,7 +387,7 @@ You can also use C<while> in a post-condition:
 
 Exactly like C:
 
-    for ($i=0; $i <= $max; $i++) {
+    for ($i = 0; $i <= $max; $i++) {
         ...
     }
 
@@ -383,6 +407,9 @@ the more friendly list scanning C<foreach> loop.
         print "The value of $key is $hash{$key}\n";
     }
 
+The C<foreach> keyword is actually a synonym for the C<for>
+keyword.  See C<L<perlsyn/"Foreach Loops">>.
+
 =back
 
 For more detail on looping constructs (and some that weren't mentioned in
@@ -437,7 +464,7 @@ before 99).
     !   not
 
 (C<and>, C<or> and C<not> aren't just in the above table as descriptions
-of the operators -- they're also supported as operators in their own
+of the operators.  They're also supported as operators in their own
 right.  They're more readable than the C-style operators, but have
 different precedence to C<&&> and friends.  Check L<perlop> for more
 detail.)
@@ -475,8 +502,8 @@ the list:
     my $line  = <$in>;
     my @lines = <$in>;
 
-Reading in the whole file at one time is called slurping. It can
-be useful but it may be a memory hog. Most text file processing
+Reading in the whole file at one time is called slurping.  It can
+be useful but it may be a memory hog.  Most text file processing
 can be done a line at a time with Perl's looping constructs.
 
 The C<< <> >> operator is most often seen in a C<while> loop:
@@ -531,7 +558,7 @@ expressions.  These are documented at great length in L<perlre>, but for
 the meantime, here's a quick cheat sheet:
 
     .                   a single character
-    \s                  a whitespace character (space, tab, newline)
+    \s                  a whitespace character (space, tab, newline, ...)
     \S                  non-whitespace character
     \d                  a digit (0-9)
     \D                  a non-digit
@@ -636,7 +663,7 @@ For more information on writing subroutines, see L<perlsub>.
 OO Perl is relatively simple and is implemented using references which
 know what sort of object they are based on Perl's concept of packages.
 However, OO Perl is largely beyond the scope of this document.
-Read L<perlboot>, L<perltoot>, L<perltooc> and L<perlobj>.
+Read L<perlootut> and L<perlobj>.
 
 As a beginning Perl programmer, your most common use of OO Perl will be
 in using third-party modules, which are documented below.
@@ -653,7 +680,7 @@ to database integration to graphics.  A categorized list of modules is
 also available from CPAN.
 
 To learn how to install modules you download from CPAN, read
-L<perlmodinstall>
+L<perlmodinstall>.
 
 To learn how to use a particular module, use C<perldoc I<Module::Name>>.
 Typically you will want to C<use I<Module::Name>>, which will then give