Closed p5pRT closed 21 years ago
perldata.pod gives this as one of its examples of a hash slice:
foreach (@hash{keys %hash}) { s/^\s+//; # trim leading whitespace s/\s+$//; # trim trailing whitespace s/(\w+)/\u\L$1/g; # "titlecase" words }
Surely this isn't a good example\, as (I think - what am I missing?)
foreach (values %hash) { ... }
is a more sane way of writing that particular construction\, and I don't feel that adding another paragraph to the pod reminding users of values is a good idea.
Nicholas Clark
What you are missing is that you hadn't tried it on an older Perl:
perl5.005 -lw %h = (a => 1\, b => 2); foreach (values %h) { $_++ }; print %h; __END__ a1b2
perl5.6.0 -lw %h = (a => 1\, b => 2); foreach (values %h) { $_++ }; print %h; __END__ a2b3
So it used to be an essential trick\, now obsolete.
Perhaps the example should be commented "This was necessary in Perl versions \< 5.6" ?
Mike Guy
What you are missing is that you hadn't tried it on an older Perl:
So it used to be an essential trick\, now obsolete.
Perhaps the example should be commented "This was necessary in Perl versions \< 5.6" ?
Ah. What I had found was that the whole section isn't in the 5.005_03 man page. Hmm. How confusing.
Nicholas Clark
http://rt.perl.org/rt2/Ticket/Display.html?id=7213
Nearly two years later\, Nicholas is right. :-)
Casey West
-- If you don't double-click me\, I can't do anything. -- John Aniston\, on how computers have taken over his life
On Thu\, Apr 24\, 2003 at 08:42:32PM -0400\, Casey West wrote:
http://rt.perl.org/rt2/Ticket/Display.html?id=7213 --- perl-current.orig/pod/perldata.pod Mon Mar 4 04:18:27 2002 +++ perl-current/pod/perldata.pod Thu Apr 24 20:35:56 2003 @@ -644\,7 +644\,7 @@
foreach \(@​array\[ 4 \.\. 10 \]\) \{ s/peter/paul/ \}
- foreach (@hash{keys %hash}) { + foreach (values %hash) { s/^\s+//; # trim leading whitespace s/\s+$//; # trim trailing whitespace s/(\w+)/\u\L$1/g; # "titlecase" words
The problem is you're no longer demonstrating that the results of a hash slice is an lvalue.
Maybe:
foreach (@hash{qw/title subtitle/}) {
(still not a great example)
Tony
It was Friday\, April 25\, 2003 when Tony Cook took the soap box\, saying:
: On Thu\, Apr 24\, 2003 at 08:42:32PM -0400\, Casey West wrote:
: > http://rt.perl.org/rt2/Ticket/Display.html?id=7213
: > --- perl-current.orig/pod/perldata.pod Mon Mar 4 04:18:27 2002
: > +++ perl-current/pod/perldata.pod Thu Apr 24 20:35:56 2003
: > @@ -644\,7 +644\,7 @@
: >
: > foreach (@array[ 4 .. 10 ]) { s/peter/paul/ }
: >
: > - foreach (@hash{keys %hash}) {
: > + foreach (values %hash) {
: > s/^\s+//; # trim leading whitespace
: > s/\s+$//; # trim trailing whitespace
: > s/(\w+)/\u\L$1/g; # "titlecase" words
:
: The problem is you're no longer demonstrating that the results of a hash
: slice is an lvalue.
:
: Maybe:
:
: foreach (@hash{qw/title subtitle/}) {
Indeed\, I was too quick to judge the dubious construct. Here is a better patch.
Casey West
-- "Louis Pasteur's theory of germs is ridiculous fiction". -- Pierre Pachet\, Professor of Physiology at Toulouse\, 1872
Casey West wrote:
--- perl-current.orig/pod/perldata.pod Mon Mar 4 04:18:27 2002 +++ perl-current/pod/perldata.pod Thu Apr 24 21:22:01 2003
Thanks\, applied as #19344\, along with other docs patches (tickets 21785 and 21260)
@rgs - Status changed from 'open' to 'resolved'
Migrated from rt.perl.org#7213 (status was 'resolved')
Searchable as RT7213$