On Saturday, August 23, 2003, at 11:14 , Sean O'Rourke wrote:

Luke Palmer <[EMAIL PROTECTED]> writes:

Gordon Henriksen writes:
        my $ref = [EMAIL PROTECTED];
        $$ref = "value";
        print '@ary[0] : ', @ary[0], "\n";   # -> @ary[0] : value

That has to do with autovivification semantics. Particularly, do things
autovivify when you take a nonconstant reference to them.

I think it's better seen as part of the semantics of references to nonexistent values. When you take a ref to a value slot that doesn't exist, you effectively create a tied variable that knows how to create that slot, and will do so only when you assign to it.

Really? I'd think that it would create the slot immediately. Perl 5 does.


        perl <<'EOT'
                my %hash;
                my $ref = \$hash{key};
                print exists $hash{key}? "exists\n" : "DNE\n";
        EOT
        exists

Also means that this...

my $ref = \%hash{blah}{blort}[123]{moogle};

is just a chain of autovivifying subscript operations, rather than the construction of some horribly complex object that knows how to create all of those intermediate aggregates. Also means that this

%hash{blah}{blort}[123]{moogle} = 1;

work's just the same way as the reference creation (up until it assigns a value instead of creating a reference object).


OTOH, this in Perl 5


my $val = $hash{blah}{blort}[123]{moogle};

Was always annoyingly non-orthogonal to simpler constructs, in that it vivified all but the last container. But that's separately solvable.



Gordon Henriksen
[EMAIL PROTECTED]

Reply via email to