in reply to Creating a random generator

From what you shown here, and your list of programming goals, you would be well served by looking into using Template::Toolkit. It's perfect for generating html output from perl scripts, and you can talk to databases from it, which would be good for your attributes pages. I haven't looked at all your projects, but from what I've seen so far I would use a mysql back end and DBI, Template::Toolkit to generate pages, and CGI.pm to handle the form submission. I do realize you're fairly new to perl and that's a daunting list, but it's not bad if you take it one piece at a time. I highly recommend the O'Reilly book 'Perl Template Toolkit'.

Replies are listed 'Best First'.
Re^2: Creating a random generator
by Lady_Aleena (Priest) on Oct 05, 2007 at 07:29 UTC

    I have looked into an gotten installed HTML::Template, which may do the same thing as Template::Toolkit. I still don't know how to make or use databases just yet, but I am going to get to it very soon, since I will more than likely need it before this is all over. I do not have MySQL and a lot of other things that everyone recommends on my server. I am already using use CGI in my scripts.

    I am learning Perl by using it to do those projects. It is the best way for me to learn, since the subject matter holds my interest more than print "Hello World!\n\n"; amongst other things. I build scripts to have them torn down by my betters and shown what I did poorly or wrong. I am glad that there are people here who understand that some of us can't learn from the abstract, we need to put into a familiar subject right away to learn.

    Thanks for dropping me a line.

    Lady Aleena

    "An it harm none, do as ye will."

      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

        UnstoppableDrew;

        Before this goes too much further, MySQL is unavailable to me. It looks great, but I would need it to be pure Perl. Also, other things will be happening once I get the table to print, like having select boxes where the users can choose which proficiencies that they want to see.

        Great work! Have a splendid day...

        Lady Aleena

        "An it harm none, do as ye will."

      Hmm...I just looked at HTML::Template. You'd be way better off learning Template Toolkit over that.

        UnstoppableDrew;

        Are there significan't differences?

        Lady Aleena

        "An it harm none, do as ye will."