use strict; use warnings; BEGIN{ package Team { sub new{ my ($class, $type, $name) = @_; #print "IN ", __PACKAGE__ , " Creating a $type named $na +me (Class=$class)\n"; return bless{TYPE=>$type, NAME=>$name}, $class; } sub name{return $_[0]->{NAME}}; sub type{return $_[0]->{TYPE}}; sub Print{my ($o)=@_; print qq|I am a |, ref($o), qq| named |, + $o->name(), qq| of type |,$o->type(),qq|\n|;}; 1; } # Create derived packages for "Team" for my $t(qw|NFL NBA MLB|){ eval << " __TEAMS__"; package $t { use base "Team"; sub new {bless Team::->new('$t',\$_[1]), "$t" } 1; } __TEAMS__ $@ and print "Eval err(package $t):$@\n"; } package Restaurant{ sub new{ my ($class, $type, $name) = @_; #print "IN ", __PACKAGE__ , " Creating a $type named $na +me (Class=$class)\n"; return bless{TYPE=>$type, NAME=>$name}, $class; } sub name{return $_[0]->{NAME}}; sub type{return $_[0]->{TYPE}}; sub Print{my ($o)=@_; print qq|I am a |, ref($o), qq| named |, + $o->name(), qq| of type |,$o->type(),qq|\n|;}; } # Create derived packages for "Restaurant" for my $t(qw|FASTFOOD FINEDINING MIDRANGE|){ eval << " __TEAMS__"; package $t { use base "Restaurant"; sub new {bless Restaurant::->new('$t',\$_[1]), "$t" } 1; } __TEAMS__ $@ and print "Eval err(package $t):$@\n"; } } my @teams = (map ({ NFL::->new($_) } qw|JETS PATRIOTS GIANTS| ), map ({ MLB::->new($_) } qw|YANKEES METS CARDINALS| ), map ({ NBA::->new($_) } qw|SIXERS CELTICS LAKERS| ) ); print "--- Teams ---\n"; $_->Print() for @teams; my @restaurants = ( map ({ FASTFOOD::->new($_) } qw|WENDYS MCDONALDS + BURGER KING| ), map ({ FINEDINING::->new($_) } 'GRILL 23' , 'CAPIT +AL GRILL' , 'MORTONS' ), map ({ MIDRANGE::->new($_) } 'OUTBACK', 'TEXAS R +OADHOUSE', 'CHILIS' ) ); print "-- Restaurants --\n"; $_->Print() for @restaurants;
--- Teams --- I am a NFL named JETS of type NFL I am a NFL named PATRIOTS of type NFL I am a NFL named GIANTS of type NFL I am a MLB named YANKEES of type MLB I am a MLB named METS of type MLB I am a MLB named CARDINALS of type MLB I am a NBA named SIXERS of type NBA I am a NBA named CELTICS of type NBA I am a NBA named LAKERS of type NBA -- Restaurants -- I am a FASTFOOD named WENDYS of type FASTFOOD I am a FASTFOOD named MCDONALDS of type FASTFOOD I am a FASTFOOD named BURGER of type FASTFOOD I am a FASTFOOD named KING of type FASTFOOD I am a FINEDINING named GRILL 23 of type FINEDINING I am a FINEDINING named CAPITAL GRILL of type FINEDINING I am a FINEDINING named MORTONS of type FINEDINING I am a MIDRANGE named OUTBACK of type MIDRANGE I am a MIDRANGE named TEXAS ROADHOUSE of type MIDRANGE I am a MIDRANGE named CHILIS of type MIDRANGE
...it is unhealthy to remain near things that are in the process of blowing up. man page for WARP, by Larry Wall
In reply to Re: How to define and deref hash of hash of hash
by NetWallah
in thread How to define and deref hash of hash of hash
by dirtdog
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |