[VPM] question about possible Perl runtime bug

Darren Duncan darren at DarrenDuncan.net
Sun Jul 6 21:07:24 CDT 2003

Hello.  I have found a situation, when using both Perl 5.6.0 and 5.6.1, which suggests that Perl is executing something that I would expect to be an error.  

Please see the following, simplified example:

	use strict;
	use warnings;
	sub myfunc {
		_myfunc( 5, {} );
	sub _myfunc {
		my ($count,$gotten_already) = @_;
		print "args are '$count' and '$gotten_already'\n";
		$gotten_already->{$count} = 1;
		print "size is ".(keys %{$gotten_already})."\n";
		if( $count > 0 ) {
			if( $count == 3 ) {
				_myfunc( $count );
			} else {
				_myfunc( $count,$gotten_already );

When I run that code, I get the following output:

	args are '5' and 'HASH(0x80fe22c)'
	size is 1
	args are '4' and 'HASH(0x80fe22c)'
	size is 2
	Use of uninitialized value in concatenation (.) or string at - line 10.
	args are '3' and ''
	size is 1
	args are '2' and 'HASH(0x811e73c)'
	size is 2
	args are '1' and 'HASH(0x811e73c)'
	size is 3

What I am expecting is for Perl to die after printing the second output line.  On the third invocation of _myfunc(), "$gotten_already" contains an undefined value, because it wasn't passed one.  However, the interpreter still treats the variable as a valid hash reference, even though I never passed one in.

Considering that I am using strict, why is automatically creating a hash ref when I try to use it without scolding me for not explicitely declaring/creating the hash ref first?  Is this a bug?  Or is it so-called "proper behaviour"?

Thanks for any light you can shed on this. -- Darren Duncan

More information about the Victoria-pm mailing list