I'm a little late to this party - but it was fun to try to make this Object Oriented...
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;
Which prints this output:
--- 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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.