in reply to autoload usage
for eg,
If you defined your autoload subroutine like above inside any of your package, you are reducing lot of coding, because with the help of above routine you achieve some thing like this.sub AUTOLOAD { my $Self = $_[0]; my $CalledAs = $AUTOLOAD; $CalledAs =~ s/^.*:://; return if $CalledAs =~ /DESTROY/; $code = qq { sub $CalledAs { my \$Self = \$_[0]; \@_ > 1 ? \$Self->{\$CalledAs} = \$_[1]: \$Self->{\$Called +As} ; } }; eval $code; if($@){ die "Error defining sub routine, $CalledAs,$code, $@\n"; } goto &{$AUTOLOAD}; }
$SomeObject->name("john");
# will set hash $SomeObject's hash like $SomeObject{'name'} = "john";
# later you can retrieve the value using
$SomeObject->name(); # will return "john";
easy isn't it.
but defining a sub-routine for every attribute like name, age, address, etc., is quite faster in terms of access than this way of creating subroutine in autoload. But the above method reduces lot of code.
|
|---|