Here is the hash as I would like it with the "default" book as a scalar, and used in the hash. I hope that works.
my $MM = "Monstrous Manual" my %monster_lookup = ( 'beholder' => { book => $MM, beholder => 1, page => 21, }, 'death kiss' => { book => $MM, beholder => 0, page => 21, }, 'eye of the deep' => { book => $MM, beholder => 0, page => 21, }, 'gauth' => { book => $MM, beholder => 0, page => 21, }, 'spectator' => { book => $MM, beholder => 0, page => 21, }, 'undead' => { book => $MM, beholder => 0, page => 21, }, 'hive mother' => { book => $MM, beholder => 0, page => 25, }, 'director' => { book => $MM, beholder => 0, page => 25, }, 'examiner' => { book => $MM, beholder => 0, page => 25, }, 'lensman' => { book => $MM, beholder => 0, page => 25, }, 'overseer' => { book => $MM, beholder => 0, page => 25, }, 'watcher' => { book => $MM, beholder => 0, page => 25, }, );

Would Perl be okay with the following?

my $MM = "Monstrous Manual" my %monster_lookup = ( 'beholder' => {book => $MM,beholder => 1,page => 21,}, 'death kiss' => {book => $MM,beholder => 0,page => 21,}, 'eye of the deep' => {book => $MM,beholder => 0,page => 21,}, 'gauth' => {book => $MM,beholder => 0,page => 21,}, 'spectator' => {book => $MM,beholder => 0,page => 21,}, 'undead' => {book => $MM,beholder => 0,page => 21,}, 'hive mother' => {book => $MM,beholder => 0,page => 25,}, 'director' => {book => $MM,beholder => 0,page => 25,}, 'examiner' => {book => $MM,beholder => 0,page => 25,}, 'lensman' => {book => $MM,beholder => 0,page => 25,}, 'overseer' => {book => $MM,beholder => 0,page => 25,}, 'watcher' => {book => $MM,beholder => 0,page => 25,}, );

What I really want with the book key is that if it is empty, then the default book, else what is in the book in the key.

The argument between using package or lexical variables can continue at a later time.

Corrections:

Update


In reply to Re^7: Creating a random generator by Lady_Aleena
in thread Creating a random generator by Lady_Aleena

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.