A simplification of your code. You are repeating the same action using different data. So rather than have lots of code lets focus on a data structure that uses the same code.

my %effects = ( part => [qw(acid cold electricity fire)], gaze => [qw(paralysis stone stun death)], range_part => [qw(gas sonic)], touch_part => ['poison', 'energy drain'], touch_special => ['befouls', 'purifies', 'nullifies holy water', 'nu +llifies unholy water'], vocal => [qw(deafen fear terror flight)], ); $effects{'range'} = [@{$effects{'part'}}, @{$effects{'range_part'}}] +; $effects{'touch'} = [@{$effects{'part'}}, @{$effects{'touch_part'}}] +; $effects{'general'} = [@{$effects{'part'}}, @{$effects{'touch_part'}}, @{$effects{'gaze'}}, @{$effects{'range_part'}}, @{$effects{'vocal'}}]; sub random_effect { my $type = shift; return 'unknown' if not exists $effects{ $type }; return $effects{ $type }[ rand @{$effects{ $type }} ]; } print random_effect('misspelled') . "\n"; print random_effect( 'touch' ) . "\n"; print random_effect( 'touch' ) . "\n"; print random_effect( 'general' ) . "\n"; print random_effect( 'general' ) . "\n";

Now if you want to add a effect type, you only need to add an entry into %effects. You could probably do something similar for the alignments.


In reply to Re: Lady Aleena's first working module by Herkum
in thread Lady Aleena's first working module 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.