New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
map {chop; $_} (Literals problem) #2079
Comments
From pdcawley@rt158.private.realtime.co.ukCreated by @pdcawleySo, I'm trying to install Coy.pm under perl 5.6.0 and it throws an $ /usr/local/bin/perl5.6.0 -le 'print map {chop; $_} (Word)' throws a 'Modification of a read-only value attempted at -e line 1' $ /usr/bin/perl5.00503 -le 'print map {chop; $_} (Word)' happily prints out: Wor One of these behaviours is presumably a bug... Perl Info
|
From [Unknown Contact. See original ticket]pdcawley@rt158.private.realtime.co.uk writes:
perlfunc.pod (on grep and map) says quite clearly that $_ is a Try this with perl5.00503: for( my $i=1; $i <=2; $i++ ){ Note that No run-time error (but a somewhat counter-intuitive result) is produced Cheers, |
From [Unknown Contact. See original ticket]Wolfgang Laun <Wolfgang.Laun@alcatel.at> wrote
... which is somewhat misleading, not to say plain wrong. $_ is an
I've never understood this "named array" business. Surely an Patch for perl-current attached. Mike Guy Inline Patch--- ./pod/perlfunc.pod.orig Tue May 30 15:02:58 2000
+++ ./pod/perlfunc.pod Mon Jun 12 14:47:54 2000
@@ -2078,9 +2078,9 @@
@foo = grep {!/^#/} @bar; # weed out comments
-Note that, because C<$_> is a reference into the list value, it can
-be used to modify the elements of the array. While this is useful and
-supported, it can cause bizarre results if the LIST is not a named array.
+Note that C<$_> is an alias to the list value, so it can be used to
+modify the elements of the LIST. While this is useful and supported,
+it can cause bizarre results if the elements of LIST are not variables.
Similarly, grep returns aliases into the original list, much as a for
loop's index variable aliases the list elements. That is, modifying an
element of a list returned by grep (for example, in a C<foreach>, C<map>
@@ -2462,9 +2462,9 @@
$hash{getkey($_)} = $_;
}
-Note that, because C<$_> is a reference into the list value, it can
-be used to modify the elements of the array. While this is useful and
-supported, it can cause bizarre results if the LIST is not a named array.
+Note that C<$_> is an alias to the list value, so it can be used to
+modify the elements of the LIST. While this is useful and supported,
+it can cause bizarre results if the elements of LIST are not variables.
Using a regular C<foreach> loop for this purpose would be clearer in
most cases. See also L</grep> for an array composed of those items of
the original list for which the BLOCK or EXPR evaluates to true.
End of patch |
From [Unknown Contact. See original ticket]mjtg@cus.cam.ac.uk wrote:
Since I did not write that in the first place I have no heart in defending it.
Did you run the code snippet at the end of my 1st mail? #! /usr/bin/perl -w Surely this is "a list of scalar variables". So, to be on the safe side, the list itself Thank you, |
From @tamiasOn Mon, Jun 12, 2000 at 04:51:51PM +0200, Wolfgang Laun wrote:
I wouldn't call those results bizarre. Those are exactly the results you my $w = 'Word'; (BTW, you had a control character in the middle of your code snippet.) Ronald |
From [Unknown Contact. See original ticket]*********** REPLY SEPARATOR *********** On 12.06.00 at 10:58 Ronald J Kimball wrote:
I'm not aware that I called them "bizarre" (I did NOT write perlfunc.pod). In my mail I was
Well, did you see that before you ran the code? If so: how did you acquire that insight in the first place?
Cut and paste on Windows 98 - which I don't normally use.
Cheers, |
From @iabyn(Just reviewing old bugs) SInce the docs have been updated to reflect reality, I guess this call Dave M. |
@iabyn - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#3365 (status was 'resolved')
Searchable as RT3365$
The text was updated successfully, but these errors were encountered: