Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Herkum,

Thanks for simplifying my code. While I didn't do exactly what you did above, I did use the hash.

For Alignment.pm...

my %alignment = ( parts => [qw(lawful chaotic good evil neutral)], good_vs_evil => [qw(good neutral evil)], lawful_vs_chaotic => [qw(lawful neutral chaotic)], ); $alignment{'evil'} = [map($_." evil",@{$alignment{'lawful_vs_chaotic'} +})]; $alignment{'good'} = [map($_." good",@{$alignment{'lawful_vs_chaotic'} +})]; $alignment{'chaotic'} = [map("chaotic ".$_,@{$alignment{'good_vs_evil' +}})]; $alignment{'lawful'} = [map("lawful ".$_,@{$alignment{'good_vs_evil'}} +)]; $alignment{'neutral_lc'} = [map($_." neutral",grep {$_ ne "neutral"} @ +{$alignment{'lawful_vs_chaotic'}}), "true neutral"]; $alignment{'neutral_ge'} = [map("neutral ".$_,grep {$_ ne "neutral"} @ +{$alignment{'good_vs_evil'}}), "true neutral"]; sub full { my $prefix = $alignment{'lawful_vs_chaotic'}[rand @{$alignment{'lawf +ul_vs_chaotic'}}]; my $suffix = $alignment{'good_vs_evil'}[rand @{$alignment{'good_vs_e +vil'}}]; if ($prefix eq $suffix) { return "true neutral"; } else { return $prefix." ".$suffix; } } sub random_alignment { my $type = shift; my $result; if (exists $alignment{$type}) { $result = $alignment{$type}[rand @{$alignment{$type}}]; } else { $result = &full; } return $result; }

For Effect.pm...

my %effects = ( part => [qw(acid cold electricity fire)], gaze => [qw(paralysis stone stun death)], range_part => [qw(gas sonic)], touch_part => [qw(poison energy_drain)], touch_special => [qw(befouls purifies nullifies_holy_water nullifies +_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{'gaze'}}, @{$ef +fects{'range_part'}}, @{$effects{'touch_part'}}, @{$effects{'vocal'}} +]; sub random_effect { my $type = shift; my $result; if (exists $effects{$type}) { $result = $effects{$type}[rand @{$effects{$type}}]; } else { $result = $effects{'general'}[rand @{$effects{'general'}}]; } $result =~ tr/_/ /; return $result; }

If there are any further improvements you can think of, please let me know. Thanks again!

Have a nice day!
Lady Aleena

In reply to Re^2: Lady Aleena's first working module by Lady_Aleena
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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-03-28 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found