develooper Front page | perl.perl5.porters | Postings from March 2000

[PATCH] Re: //p vs ($??{ }) vs ...

From:
M.J.T. Guy
Date:
March 14, 2000 09:28
Subject:
[PATCH] Re: //p vs ($??{ }) vs ...
Message ID:
E12Uv7S-0000ZX-00@ursa.cus.cam.ac.uk
Tom Christiansen <tchrist@chthon.perl.com> wrote
> "Interpolation" has *never* meant "used as a string" in Perl, and
> consequently, the current perlre documentation is wrong in this
> respect and should be amended.

No, it never has meant that.   It's meant "inserted into a string".
And as such it's a well established and widely used Perlism.
Perhaps it is linguistically inaccurate, but given the widespead usage
it wouuld be a mistake to change it.

> Proof:
>
>     LISTs do automatic interpolation of sublists.  That is, when a
>     LIST is evaluated, each element of the list is evaluated in
>     list context, and the resulting list value is interpolated into
>     LIST just as if each individual element were a member of LIST.
>     Thus arrays and hashes lose their identity in a LIST.

All that proves is that the perldata man page can be misleading.
That's the sort of talk which compounds peoples difficulties with
context and with operator precedence, and leads to mistaken beliefs
such as "commas make lists" or "brackets make lists".
What we have here is a number of occurences of the comma operator in
list context.    And the comma operator simply concatenates its
arguments.     No interpolation at all.

I attach a suggested reword of that paragraph (with some other tidies
noticed in passing).     Patch is for 5.6-rc1.


Mike Guy

--- ./pod/perldata.pod.orig	Tue Mar 14 17:24:14 2000
+++ ./pod/perldata.pod	Tue Mar 14 17:19:10 2000
@@ -138,8 +138,8 @@
 
 User-defined subroutines may choose to care whether they are being
 called in a void, scalar, or list context.  Most subroutines do not
-need to bother, though.  That's because both scalars and lists are
-automatically interpolated into lists.  See L<perlfunc/wantarray>
+need to bother, though.  That's because most Perl expressions have
+a sensible value in either context.  See L<perlfunc/wantarray>
 for how you would dynamically discern your function's calling
 context.
 
@@ -338,7 +338,7 @@
 The special literals __FILE__, __LINE__, and __PACKAGE__
 represent the current filename, line number, and package name at that
 point in your program.  They may be used only as separate tokens; they
-will not be interpolated into strings.  If there is no current package
+are not interpolated in strings.  If there is no current package
 (due to an empty C<package;> directive), __PACKAGE__ is the undefined
 value.
 
@@ -498,23 +498,22 @@
 	white wine
     End_Lines
 
-LISTs do automatic interpolation of sublists.  That is, when a LIST is
-evaluated, each element of the list is evaluated in list context, and
-the resulting list value is interpolated into LIST just as if each
-individual element were a member of LIST.  Thus arrays and hashes lose their
-identity in a LIST--the list
+A LIST is just a series of applications of the list context variety
+of the comma operator.   So each element of the list is evaluated in
+list context, and the resulting lists concatenated.   Thus arrays and
+hashes lose their identity in a LIST--the list
 
     (@foo,@bar,&SomeSub,%glarch)
 
 contains all the elements of @foo followed by all the elements of @bar,
 followed by all the elements returned by the subroutine named SomeSub 
 called in list context, followed by the key/value pairs of %glarch.
-To make a list reference that does I<NOT> interpolate, see L<perlref>.
+To make a list reference that retains its identity, see L<perlref>.
 
-The null list is represented by ().  Interpolating it in a list
+The null list is represented by ().  As part of a list, it
 has no effect.  Thus ((),(),()) is equivalent to ().  Similarly,
-interpolating an array with no elements is the same as if no
-array had been interpolated at that point.
+an array with no elements is the same as if the list element wasn't
+there.
 
 A list value may also be subscripted like a normal array.  You must
 put the list in parentheses to avoid ambiguity.  For example:

End of patch



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About