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

Re: [ID 20000317.003] missing slice of reference

From:
M.J.T. Guy
Date:
March 17, 2000 06:26
Subject:
Re: [ID 20000317.003] missing slice of reference
Message ID:
E12Vxhv-00026N-00@ursa.cus.cam.ac.uk
JVromans@squirrel.nl (Johan Vromans) wrote
> It is even worse. The following program compiles and runs with only
> one warning: that @a[2] should be written as $a[2]. @a->[2] is
> accepted, without complaint, to apparently mean $a[2].

I recall from the last time this came up that it's an accidental
feature.    If the LHS of -> is an array or hash, it's treated as if
it were a reference to that array or hash.    I think it hasn't been
removed for fear of breakage.

But it certainly ought to be documented.    Patch attached.

And I wouldn't mind seeing a warning for that.

>                                                        And I cannot
> see why 'scalar(@x)->[2]' produces the 3rd element of array @x.

Where does it say anything about scalar context?


Mike Guy


--- ./pod/perlop.pod.orig	Mon Mar 13 21:39:26 2000
+++ ./pod/perlop.pod	Fri Mar 17 14:20:58 2000
@@ -101,7 +101,10 @@
 symbolic reference to an array, a hash, or a subroutine respectively.
 (Or technically speaking, a location capable of holding a hard
 reference, if it's an array or hash reference being used for
-assignment.)  See L<perlreftut> and L<perlref>.
+assignment.)  See L<perlreftut> and L<perlref>.    Currently,
+the left hand side may also be an array or hash; it's treated as
+if it were a reference to that array or hash.    But that's an
+accidental feature which may disappear in future Perls.
 
 Otherwise, the right side is a method name or a simple scalar
 variable containing either the method name or a subroutine reference,

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