On Tue, Jan 28, 2003 at 03:06:19PM -0800, Damian Conway wrote:
> Austin Hastings wrote:
> 
> >--- Damian Conway <[EMAIL PROTECTED]> wrote:
> >
> >>    my @a is default(666);
> >>
> >>    print @a[2];    # prints 666
> >>
> >>    @a[4] = 1;
> >>
> >>    print @a[2];    # now prints undef :-(
> 
> [typo in third line corrected]
> 
> 
> >I don't understand your example. Can you explain it again, using words
> >of less than one syllable?
> 
> If the scheme is (as someone was advocating) that the default is used only 
> in place of elements that don't exist (as opposed to elements that are 
> allocated but contain C<undef>), then allocating a previously unallocated 
> element has the potential to change the value it returns, even if that 
> previously unallocated element is not initialized when allocated.
> 
> So, assigning to @a[4], causes @a[0..3] to be created as well. Which,
> under a "default-for-non-existent-elements-only" policy causes @a[2] to stop
> returning the default.

It doesn't have to be that way:

$ perl -le 'sub e { print exists $a[shift] ? 1 : 0 } e 2; $a[4]++; e 2; e 4; delete 
$a[4]; e 2; e 4'
0
0
1
0
0

No, I don't know which side I'm arguing anymore :-)

Actually, I do.  I don't like exists on arrays.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

Reply via email to