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

Re: [perl #27392] 5.8.2 cores or loops using hashref as subscript

Thread Previous
From:
Brent "Dax" Royal-Gordon
Date:
March 4, 2004 20:33
Subject:
Re: [perl #27392] 5.8.2 cores or loops using hashref as subscript
Message ID:
404802F8.9030103@brentdax.com
> 	foreach (@{$G->{A}{B}} ){
> 		print "X: $_\n";
> 		$G->{A}{B}[$_]{C};
> 	}

The hashref is being evaluated as a number, which returns the numeric 
address of the referee.

On HP-UX, that means you're trying to access an array element with index 
1,073,867,976.  Presumably, HP-UX is refusing to allocate 1,073,867,977 
scalars, making ary[1,073,867,976] (or thereabouts) a bad pointer.  (I 
don't know whether 'ary' is null or not, and I'm not really in a 
position to check--I don't have a Perl with debug symbols handy.)

On OS X, you're trying to access element 2,667,044.  Apparently this is 
okay on your box (although I'm guessing Perl's eating a few extra 
megabytes).  However, note the caveat in L<perlsyn/Foreach Loops>:

	If any part of LIST is an array, foreach will get very confused
	if you add or remove elements within the loop body, for example
	with splice. So don't do that.

That's good advice on both of these problems, really--don't do that.

-- 
Brent "Dax" Royal-Gordon <brent@brentdax.com>
Perl and Parrot hacker

Oceania has always been at war with Eastasia.

Thread Previous


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