Class::Struct in Perl
Class::Struct grants access to one subroutine titled struct.
Using this subroutine is a handy way to get a blessed data structure in Perl.
The idea is that the data structure is given a class name as well as a list of hash keys and respective sigils.
I find this subroutine to be smooth as silk. This is a useful addition to the Modern Perl programmer's utility belt.
use Class::Struct;
struct Person {
name => '$',
age => '$',
peers => '@',
};
my $p = Person->new();
$p->name("Jason Smythe");
$p->age(13);
$p->peers( ["Wilbur", "Ralph", "Fred"] ) ;
# or this way
@{$p->peers} = ("Wilbur", "Ralph", "Fred");
printf "At age %d, %s's first friend is %s.\n", $p->age, $p->name, $p->peers(0);
Written by Jason McVeigh
Related protips
2 Responses
I made this!
over 1 year ago
·
I ♥ what I do and I hope you do too!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Perl class structure bless blessed
Authors
Related Tags
#perl class structure bless blessed
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#