develooper Front page | perl.perl5.porters | Postings from May 2004

Re: my $x->{foo} doesn't work

Thread Previous | Thread Next
Rafael Garcia-Suarez
May 21, 2004 01:50
Re: my $x->{foo} doesn't work
Message ID:
20040521104754.48946e94@localhost wrote:
> I love my variable and am looking for various ways of using it.
> I will show you a bit of code.
> $ perl -e 'my $x;$x->{foo}'     # OK
> $ perl -e '(my $x)->{foo}'      # NG
> I expected that autovivification would be applied to the
> variable in the later case as well as in the first case, but
> the results were different.

If you look at what contexts permit and forbid autovivification, you'll
see that the situation in perl is currently complex and probably not
very consistent. Anyway, in general lvalue contexts don't permit it; a
lexical declaration can be seen as this; and you still can write, in a
rather obfuscated way,

    (my $x = {}) -> {foo}

Your patch looks correct at a first glance, but I'm not very inclined to
apply it, unless the crowd comes up with good reasons why to.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About