So I had some free time, and I haven't written any code for fun in a while, so I decided to put my money where my mouth is. Here's the skeleton of a solution for your proficiency tables. I created a mysql database named 'player', and create one table called 'proficiencies':
mysql> describe proficiencies; +-------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------------+-------------+------+-----+---------+-------+ | proficiency | varchar(50) | NO | | | | | s | int(11) | YES | | NULL | | | ra | varchar(20) | NO | | | | | cm | int(11) | YES | | NULL | | | class | varchar(30) | YES | | NULL | | | source | varchar(30) | YES | | NULL | | +-------------+-------------+------+-----+---------+-------+
I scraped your a-c table and turned it into a text file delimited by pipe chars (since there are commas in the data):
|Acting|1|Cha|0|Bd, Hu| |Adaptation|2|Int|0|Wa 10+, R 11+|HL| |Administration|1|Int|1|Pr|SM|
I wrote a script to stuff the data into the db:
#!/usr/bin/perl use strict; use DBI; use DBD::mysql; my $dsn = "DBI:mysql:database=player;"; my $dbh = DBI->connect($dsn, "root", "secretpassword"); open IN, "<table.txt" or die "Error - failed to open file for reading: + $!\n"; while ( <IN> ) { chomp; my ($null,$prof,$s,$ra,$cm,$class,$source) = split /\|/; my $sql =<<SQLDONE ; INSERT INTO proficiencies VALUES ( '$prof', $s, '$ra', $cm, '$class', +'$source' ); SQLDONE print "$sql\n"; my $sth = $dbh->prepare($sql); $sth->execute; } print "finished loading table\n";
That was probably not the most efficient way to do it, but my dbi book is at work and all this is off the top of my head.

Script to read the database and dump data into template toolkit template:

#!/usr/bin/perl use strict; use DBI; use DBD::mysql; use Template; my $tt = Template->new(); my $dsn = "DBI:mysql:database=player;"; my $dbh = DBI->connect($dsn, "root", "secretpassword"); my @items; my $sql = qq|SELECT * from proficiencies ORDER BY proficiency ASC;|; my $sth = $dbh->prepare($sql); $sth->execute; while ( my @row = $sth->fetchrow_array() ) { push @items, \@row; } my $vars = { items => \@items }; print "Content-type: text/html\n\n"; $tt->process("prof.tmpl", $vars) or die $tt->error();
Template toolkit template to display the data:
<html> <head><title>Proficiencies</title> <body> <table border="1" cellspacing="2" cellpadding="2"> <tr> <th>Proficiency</th> <th>S</th> <th>RA</th> <th>CM</th> <th>Class(es)</th> <th>Source(s)</th> </tr> [% FOREACH row IN items %] <tr> <td align="left">[% row.0 %]</td> <td align="center">[% row.1 %]</td> <td align="center">[% row.2 %]</td> <td align="center">[% row.3 %]</td> <td align="left">[% row.4 ? row.4 : "&nbsp;" %]</td> <td align="left">[% row.5 %]</td> </tr> [% END %] </table> </body> </html>
Live script can be run by hitting this url: http://marold.org/cgi-bin/showtable.cgi

In reply to Re^3: Creating a random generator by UnstoppableDrew
in thread Creating a random generator 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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.