You're using one of my pet-peeve style errors:
sub random_alignment {
my $type = shift;
if ($type eq 'parts') {
return $parts[rand @parts];
}
elsif ($type eq 'good_vs_evil') {
return $good_vs_evil[rand @good_vs_evil];
}
elsif ($type eq 'lawful_vs_chaotic') {
return $lawful_vs_chaotic[rand @lawful_vs_chaotic];
}
After a return there can never be an else. the sub returns, so this much better reads like this:
sub random_alignment
{
my $type = shift;
if ($type eq 'parts') {
return $parts[rand @parts];
}
if ($type eq 'good_vs_evil') {
return $good_vs_evil[rand @good_vs_evil];
}
if ($type eq 'lawful_vs_chaotic') {
return $lawful_vs_chaotic[rand @lawful_vs_chaotic];
}
And personally, I'd go even further:
sub random_alignment
{
my $type = shift;
$type eq "parts" and return $parts[rand @parts];
$type eq "good_vs_evil" and return $good_vs_evil[rand @good_vs_
+evil];
$type eq "lawful_vs_chaotic" and return $lawful_vs_chaotic[rand @law
+ful_vs_chaotic];
Clean, short code. Beautiful, right?
Enjoy, Have FUN! H.Merijn
-
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.