#!/usr/bin/perl use strict; use warnings;
This is a great start to every piece of perl code. I would recommend adding the -T flag for web applications. If you don't understand what that does, read perlrun.
use CGI; use CGI::Carp qw(fatalsToBrowser);
Using CGI.pm to generate HTML is typically considered inferior to using a templating module. One advantage is keeping your data separate from your logic. Another is ease of modification. Additionally, fatalsToBrowser should almost never be used in production code - it is a security risk.
print "content-type: text/html \n\n";
Why use the CGI.pm module if you aren't really using it.
my @Dice = ( roll '1d4', roll '1d6', roll '1d8', roll '1d10', roll '1d12', roll '1d20' ); my @Dice2 = qw(1d4 1d6 1d8 1d10 1d12 1d20);
You should take a look into perlstyle and Perl::Tidy. I would have written that as:
my @Dice = qw(1d4 1d6 1d8 1d10 1d12 1d20); my @Roll = map { roll($_) } @Dice;
my @Radius = ( "1' or Touch", "5'", "10'", "20'", "50'", "100'" ); my $radius = "in a $Radius[rand @Radius] radius";
You need to work on choosing your variable names. Later on, are you going to be able to tell the difference between $radius and $Radius?
my @Wizard_School = qw(Abjuration Air Alteration Conjuration/Summoning + Divination Earth Enchantment/Charm Fire Illusion/Phantasm Invocation +/Evocation Necromancy Water); my @Cleric_Sphere = qw(Air All Animal Astral Chaos Charm Combat Creati +on Divination Earth Fire Guardian Healing Law Necromatic Numbers Plan +t Protection Summoning Sun Thought Time Travelers War Wards Water Wea +ther); my @Spell_Freq = ( "common", "uncommon", "rare", "very rare" );
You have a lot of data that appears to be static. I would look into keeping this data in distinct files and then writing a very small wrapper to load the data dynamically at run time. For instance:
sub load_array_data { my ($file, $array) = @_; open(my $fh, '<', $file) or die "Unable to open '$file' for readin +g: $!"; while (<$fh>) { chomp; push @$array, $_; } } my @Wizard_School; load_array_data('wizard.data', \@Wizard_School);
This way you can re-use the sub to load data from a file into any array you want and you can keep your code clutter free. There are modules that do this sort of thing for you so there isn't necessarily a need to write it yourself.
my @Colors = ( "f00;\">red", "ff0;\">yellow", "0f0;\">green", "0ff;\">cyan", "00f;\">blue", "f0f;\">magenta", "fff;\">white", "000;\">black" );
When you are mapping one item to another, a better data structure to use is a hash. See the following example:
my %color = ( blue => 1, green => 2, yellow => 3 red => 4, orange => 5, purple => 6 ); print "The code for green is $color{green}\n";
I believe this is more than enough to chew on for now.
Cheers - L~R
In reply to Re^2: Creating a random generator
by Limbic~Region
in thread Creating a random generator
by Lady_Aleena
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |