#!/usr/bin/perl package PKG; sub new { my $prototype = shift; # Allows for inheritence my $class = ref($prototype) || $prototype; my $self = {}; bless($self,$class); return $self; } #*AUTOLOAD=sub{$AUTOLOAD=~/:(.*?)$/&&$1ne'DESTROY'&&$_[1]?$_[0]{$1}=$_ +[1]:$_[0]{$1}}; #*AUTOLOAD=sub{$AUTOLOAD=~/:(.*?)(?<!DESTROY)$/&&$_[1]?$_[0]{$1}=$_[1] +:$_[0]{$1}}; #*AUTOLOAD=sub{$AUTOLOAD=~/:(.*?)(?<!DESTROY)$/&&($_[0]{$1}=$_[1]||$_[ +0]{$1})}; *AUTOLOAD=sub{$AUTOLOAD=~/:(.*?)(?<!DESTROY)$/&&$#_?$_[0]{$1}=$_[1]:$_ +[0]{$1}}; package MAIN; my $object = new PKG; $object->foo('bar'); print $object->foo(), "\n"; $object->foo(undef); print $object->foo(), "\n";
In reply to Short version of autoload by simon.proctor
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |