I find a lookup table is the way to go for these situations.
#!/usr/bin/perl use strict; use warnings; my $beholder_default = 'beholder'; my $param = get_param(); my @keys = ( 'beholder', 'deathkiss', 'eye of the deep', 'gauth', 'spectator', 'undead', 'hive mother', 'director', 'examiner', 'lensman', 'watcher' ); my %lookup = ( 'beholder' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'death kiss' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'eye of the deep' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'gauth' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'spectator' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'undead' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'hive mother' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'director' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'examiner' => { book => 'Monstrous Manual', beholder => 'beholder', page => 21, }, 'lensman' => { book => 'Monstrous Manual', beholder => 'beholder', page => 25, }, 'overseer' => { book => 'Monstrous Manual', beholder => 'beholder', page => 25, }, 'watcher' => { book => 'Monstrous Manual', beholder => 'beholder', page => 25, }, ); my $key; if ($param){ $key = $beholder_default; } else{ $key = $keys[rand @keys]; } my $beholder = $lookup{$key}{beholder}; my $book = $lookup{$key}{book}; my $page = $lookup{$key}{page}; print "beholder: $beholder\n"; print "book: $book\n"; print "page: $page\n"; sub get_param { # get your input from somewhere my $param = undef; return $param; }
Ah, I didn't see your update before I posted this.

In reply to Re^4: Creating a random generator by wfsp
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.