APM: Just need structs

Taylor Carpenter taylor at codecafe.com
Thu Sep 13 09:02:35 PDT 2007


Not sure if this is what you want... but it looks like a C struct  
other than the {}.  Unless you are tricky then direct access is  
always there even with subs for access each variable.  If you do not  
care to have them (eg.  name() for setting and getting the name var  
below) then just hit it directly.

If the 3 structs you need all have the same 2 fields then just do  
"new" on that object... Other-wise create 3 "packages".

BTW you can also make it so new() will take arguments and set the  
values of the variables at initialization...

	$p = new Person;
	$p->{name} = "Henry";
	print "$p->{name}\n";

	package Person;

	sub new {
		my $self = {};
		$self->{name} = undef;
		$self->{age}  = 0;
		$self->{favorite_foods} = [];
		bless($self);
		return $self;
	}


On Sep 13, 2007, at 9:53 AM, Tim McDaniel wrote:

> In C terms, all I need is three structs, each one with two fields now,
> but I may need more later.  There's no class inheritance.  I don't
> *need* getter/setter functions (it's all one program, so the caller is
> as trusted as the library), though I might implement them for
> implementation convenience.
>
> Any neato-keeno CPAN modules that you've used and that have been
> stable enough, or should I just type "man perlobj" and read?
>
> -- 
> Tim McDaniel, tmcd at panix.com
> _______________________________________________
> Austin mailing list
> Austin at pm.org
> http://mail.pm.org/mailman/listinfo/austin



More information about the Austin mailing list