Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Perl: Using Classes as Structs

Perl: Using Classes as Structs
{filelink=14328}

#!/usr/local/bin/perl -w
use Class::Struct;          # load struct module
# create a definition for a "Person" class
struct Person => {        
    fullName   => '$',
    occupation<span id="more-62"></span>    => '$',
    email    => '$',
    hobby  => '@',         # array
};
my $pers = Person->new( );      # allocate an empty Person object
$pers->fullName("Karl max");       # set 'fullName' 
$pers->occupation("devel");       # set 'occupation'
$pers->email("test@email.com");  # set 'email'
$pers->hobby( ["sport", "drink", "drive" ] ); # set 'hobby'
# fetch the values
printf "fullName:%s
 occupation: %s
 email:%s
 hobby:%s.n",
    $pers->fullName, $pers->occupation, $pers->email, ,$pers->hobby(0);

No comments yet.

Leave a Comment