perlsyn-given.patch
```diff
--- perlsyn.pod 2011-05-10 08:54:22.000000000 -0600
+++ /tmp/perlsyn.pod 2011-05-17 18:05:49.000000000 -0600
@@ -6,12 +6,13 @@
=head1 DESCRIPTION
A Perl program consists of a sequence of declarations and statements
-which run from the top to the bottom. Loops, subroutines and other
+which run from the top to the bottom. Loops, subroutines, and other
control structures allow you to jump around within the code.
-Perl is a B language, you can format and indent it however
-you like. Whitespace mostly serves to separate tokens, unlike
-languages like Python where it is an important part of the syntax.
+Perl is a B language: you can format and indent it however
+you like. Whitespace serves mostly to separate tokens, unlike
+languages like Python where it is an important part of the syntax,
+or Fortran where it is immaterial.
Many of Perl's syntactic elements are B. Rather than
requiring you to put parentheses around every function call and
@@ -31,36 +32,34 @@
X X X X
The only things you need to declare in Perl are report formats and
-subroutines (and sometimes not even subroutines). A variable holds
-the undefined value (C) until it has been assigned a defined
-value, which is anything other than C. When used as a number,
-C is treated as C<0>; when used as a string, it is treated as
-the empty string, C<"">; and when used as a reference that isn't being
-assigned to, it is treated as an error. If you enable warnings,
-you'll be notified of an uninitialized value whenever you treat
-C as a string or a number. Well, usually. Boolean contexts,
-such as:
+subroutines (and sometimes not even subroutines). A scalar variable holds
+the undefined value (C) until it has been assigned a defined value,
+which is anything other than C. When used as a number, C is
+treated as C<0>; when used as a string, it is treated as the empty string,
+C<"">; and when used as a reference that isn't being assigned to, it is
+treated as an error. If you enable warnings, you'll be notified of an
+uninitialized value whenever you treat C as a string or a number.
+Well, usually. Boolean contexts, such as:
- my $a;
if ($a) {}
are exempt from warnings (because they care about truth rather than
definedness). Operators such as C<++>, C<-->, C<+=>,
-C<-=>, and C<.=>, that operate on undefined left values such as:
+C<-=>, and C<.=>, that operate on undefined variables such as:
- my $a;
+ undef $a;
$a++;
are also always exempt from such warnings.
-A declaration can be put anywhere a statement can, but has no effect on
-the execution of the primary sequence of statements--declarations all
-take effect at compile time. Typically all the declarations are put at
-the beginning or the end of the script. However, if you're using
-lexically-scoped private variables created with C, you'll
-have to make sure
-your format or subroutine definition is within the same block scope
-as the my if you expect to be able to access those private variables.
+A declaration can be put anywhere a statement can, but has no effect on the
+execution of the primary sequence of statements: declarations all take
+effect at compile time. All declarations are typically put at the
+beginning or the end of the script. However, if you're using
+lexically-scoped private variables created with C, C, or
+C, you'll have to make sure your format or subroutine definition is
+within the same block scope as the my if you expect to be able to access
+those private variables.
Declaring a subroutine allows a subroutine name to be used as if it were a
list operator from that point forward in the program. You can declare a
@@ -70,11 +69,21 @@
sub myname;
$me = myname $0 or die "can't get myname";
-Note that myname() functions as a list operator, not as a unary operator;
-so be careful to use C instead of C<||> in this case. However, if
-you were to declare the subroutine as C, then
-C would function as a unary operator, so either C or
-C<||> would work.
+A bare declaration like that declares the function to be a list operator,
+not a unary operator, so you have to be careful to use parentheses (or
+C instead of C<||>.) The C<||> operator binds too tightly to use after
+list operators; it becomes part of the last element. You can always use
+parentheses around the list operators arguments to turn the list operator
+back into something that behaves more like a function call. Alternatively,
+you can use the prototype C<($)> to turn the subroutine into a unary
+operator:
+
+ sub myname ($);
+ $me = myname $0 || die "can't get myname";
+
+That now parses as you'd expect, but you still ought to get in the habit of
+using parentheses in that situation. For more on prototypes, see
+L
Subroutines declarations can also be loaded up with the C statement
or both loaded and imported into your namespace with a C
Migrated from rt.perl.org#90926 (status was 'resolved')
Searchable as RT90926$