Phoenix.pm: Perl Christmas Carol

Eric Thelin eric at thelin.org
Fri Dec 15 15:08:44 CST 2000


I know most of you probably read user friendly so you may have already
seen this but I thought that it was worth posting for anyone who hasn't.

By Saucepan

#!/usr/bin/perl

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

$snow = new Fields(type => 'snowy');
$sleigh= new Sleigh(horses => 1, roof => 'open');
$sleigh->dash_through($snow);
$_->laugh foreach @{ $sleigh->get_occupants };

# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

BEGIN {
package Person;
sub new { shift; bless { @_, idx => $idx++ } }
sub laugh { print "Person ", $_[0]->{idx}, " is laughing " }
package Fields;
sub new { shift; bless { @_} }
package Sleigh;
sub new { shift; bless { occupants => [new Person, new Person], @_ } }
sub get_occupants { $_[0]->{occupants} }
sub dash_through {
my($self,$what)=@_;
print $self->{horses}, " horse ", $self->{roof}," sleigh ";
print "is dashing through ", $what->{type}, "fields ";
}
}


-- 
Eric Thelin                                          erict at aztechbiz.com
AZtechBiz.com: Where Arizona Does Tech Business
Voice: 480-377-6743   Fax: 480-377-6755




More information about the Phoenix-pm mailing list