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 18, 2000 06:55
Subject:
Re: [ID 20000317.003] missing slice of reference
Message ID:
E12WKdj-00020l-00@taurus.cus.cam.ac.uk
Tom Christiansen <tchrist@chthon.perl.com> wrote
>     #!/usr/bin/perl -wl
>     @cast = (
> 	{ name => "pebbles", age  =>  2, role => "kid"	},
> 	{ name => "wilma",   age  => 31, role => "wife"	},
> 	{ name => "fred",    age  => 36, role => "husband"  },
>     );
>     print @cast->{age}->{name};
> 
> The result here, you see, is "fred", rather than the far more
> readily expected "HAVE YOU LIKE COMPLETELY LOST YOUR MIND?".

Well, I expected "fred".    But then, I'm AVHV aware.

I have lots of data structures like that (arrays of hashes), and I
regularly find that some minor bug of mine causes Perl to dive into
the AVHV code with sometimes surprising consequences (including SEGVs).

> For a good time, try to guess without running it, what prints 
> out if you interchange the subscripts:
> 
>     print @cast->{name}->{age};

Without running it, I couldn't guess exactly which error it would stop
on, but otherwise ...

> Yes, these are all bugs, not features.  But hard to fix.

Nope.   Once you've accepted @x->[2] as a shorthand for (\@x)->[2],
these are all features.    But AVHV is of course still experimental.

And it would be easy to fix  -  just remove AVHV.     :-)


Mike Guy



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