develooper Front page | perl.perl5.porters | Postings from October 2005

Re: Time to fix @foo->[0]? (was: [PATCH] Re: [perl #37350] $#{@$aref} in debugger gives: Bizarre copy of ARRAY in leave)

From:
Robin Houston
Date:
October 22, 2005 03:16
Subject:
Re: Time to fix @foo->[0]? (was: [PATCH] Re: [perl #37350] $#{@$aref} in debugger gives: Bizarre copy of ARRAY in leave)
Message ID:
20051021222549.GA30591@rpc142.cs.man.ac.uk
On Fri, Oct 21, 2005 at 09:51:08PM +0200, Abigail wrote:
> One of the features of Perl is it's DWIM. '@foo->[0]' does what people mean.
> I don't see any gain in breaking that.

Yes, I suppose this is the obvious objection, and it has some force.
The problem in this case is that the feature is an entirely accidental
byproduct of the implementation. I think Larry Wall's oft-quoted
remark applies:

 "Any [programming] language that doesn't occasionally surprise the
  novice will pay for it by continually surprising the expert."

On the other hand, it *might* be possible to make this into an
official piece of DWIMmery. Presently we understand that the
scalar value of an array is the array's length. Perhaps we could
make an exception:

 EXCEPT THAT if an array is used in a construct that expects an
 array reference, it will be treated as a reference to the array.

What are the places where such a rule would apply? @foo->[$n] of
course, and @{@foo}. Also *foo = @bar ought to behave like
*foo = \@bar (which it has never done).

Of course this is the sort of change that would need Larry's blessing,
and I imagine it would meet opposition from Perl hackers who are
attached to their current ways of thinking about array scalarification.

Robin



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