develooper Front page | perl.perl5.porters | Postings from March 2000

Re: [ID 20000317.003] missing slice of reference

From:
Tom Christiansen
Date:
March 17, 2000 19:13
Subject:
Re: [ID 20000317.003] missing slice of reference
Message ID:
29452.953349183@chthon
>As far as I can tell, scalar(@x) is 4, and 4->[2] points to nothing
>defined, most certainly not to $x[2].

It gets even richer.  

    #!/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?".

For a good time, try to guess without running it, what prints 
out if you interchange the subscripts:

    print @cast->{name}->{age};

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

--tom



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