#!/usr/local/bin/perl # Jaime Prilusky, 2003 # adapted from http://search.cpan.org/author/PRILUSKYJ/Bio-Maxd-0.04/lib/Bio/Maxd.pm package Bio::Maxd; sub new { my $self=shift; my $class=ref($self) || $self; my(%data,$tag); while (@_) { $tag = shift; if ($tag =~ /^-/) { $tag =~ s/^-//; $data{lc($tag)} = shift; } } $self = bless {} => $class; foreach $tag (keys %data) {$self->{$tag} = $data{$tag}; } return $self; } my $testObject = Bio::Maxd->new(-name => 'simple', -color=>"white"); print "name ", $testObject->{name},"\n"; # show all listed properties foreach $property qw( name sound color) { print "property $property: $testObject->{$property}\n"; } # show all properties, no previous knowledge required foreach $k (keys %{$testObject}) { print "$k $testObject->{$k}\n"; }