[Israel.pm] bless and AUTOLOAD

Yona Shlomo yona at cs.technion.ac.il
Tue Sep 25 07:50:37 PDT 2007


Hello,

I have a strange collision using bless and AUTOLOAD.

For example, here a simple Perl script, t.pl, which
demostrates my problem:

 	#!/usr/bin/perl
 	use strict;
 	use warnings;
 	use Data::Dumper;

 	my $t=T->new();

 	package T;

 	my $AUTOLOAD;

 	sub new {
 		my ($class, %arguments) = @_;
 		bless {}, $class;
 	}

 	sub AUTOLOAD {
 		print "why am I in AUTOLOAD?!\n";
 	}


Surprisingly, for me, when I run t.pl I get:
 	why am I in AUTOLOAD?!

So, why am I executing code in AUTOLOAD?

Apparently the $class is to blame in the bless statement,
but I don't know why and I don't know how to avoid this.

Anyone?

-- 
Shlomo Yona
yona at cs.technion.ac.il
http://yeda.cs.technion.ac.il/~yona/



More information about the Perl mailing list