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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.