Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Lady Aleena's first working module

by Herkum (Parson)
on Oct 05, 2009 at 21:29 UTC ( #799352=note: print w/replies, xml ) Need Help??


in reply to Lady Aleena's first working module

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.

Replies are listed 'Best First'.
Re^2: Lady Aleena's first working module
by Lady_Aleena (Curate) on Oct 14, 2009 at 21:42 UTC
    Herkum,

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

    For Alignment.pm...

    For Effect.pm...

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

    Have a nice day!
    Lady Aleena

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://799352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2021-04-20 12:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?