<?xml version="1.0" encoding="windows-1252"?>
<node id="1004917" title="Method to calculate array length" created="2012-11-21 08:27:16" updated="2012-11-21 08:27:16">
<type id="115">
perlquestion</type>
<author id="986490">
wannymahoots</author>
<data>
<field name="doctext">
I'm attempting to define a method that will calculate the length of an array stored within an object, but am running up against an issue.  In the example given below, when I call scaler on the deferenced array (which I would hope would return the array length?), the call behaves as if I'd attempted to call a method of the class called "scaler"? Clearly I'm misunderstanding something fundamental here and would really appreciate any clarification...

&lt;code&gt;
{
	package Test;
	our $AUTOLOAD;

	sub new {
		my ($class) = @_;
		return bless {arr =&gt; [1,2,3,4]}, $class;
	}
	
	sub len {
		my ($self) = @_;
		scaler(@{$self-&gt;arr});
 	}
	
	sub DESTROY {}
	
	sub AUTOLOAD {
		my ($self) = @_;
		(my $f = $AUTOLOAD) =~ s/.+://;
		print "function \"$f\" called\n";
		$self-&gt;{$f};
	}
}

my $tmp = Test-&gt;new;
print $tmp-&gt;len,"\n";
&lt;/code&gt;

Output:
&lt;code&gt;
function "arr" called
function "scaler" called
Can't use string ("1") as a HASH ref while "strict refs" in use at ./test.pl line 25.
&lt;/code&gt;</field>
</data>
</node>
