#!/usr/local/bin/perl -w # Example script using Games::Boggle::Board # Play a game of cgi-Boggle use strict; use HTML::Template; my $template; use CGI qw(param header); if ( param('board') && param('words')) { $template = HTML::Template->new(filename=>'boggle-words.template') or die; my $brd = build_board_array(param('board')); $template->param( board => $brd ); use Games::Boggle; my $board = Games::Boggle->new(param('board')); my %scores = ( 3 => 1, 4 => 1, 5 => 2, 6 => 3, 7 => 5, 8 => 11, 9 => 11, 10 => 11, 11 => 11, 12 => 11, 13 => 11, 14 => 11, 15 => 11, 16 => 11 ); my (@good, @bad); my $total_score = 0; foreach my $word ( keys %{{ map {$_ => 1} split /\s+/, param('words') }} ) { next if $word =~ /\W/; # watch for nasties if ( length($word)>2 && $board->has_word($word) ## && grep( /^$word$/, `look $word`) ) { push (@good, {word=>$word}); $total_score += $scores{length($word)}; } else { push (@bad, {word => $word}) } } $template->param( good => \@good ); $template->param( bad => \@bad ); $template->param( score => $total_score ); } else { $template = HTML::Template->new(filename=>'boggle.template') or die; use Games::Boggle::Board; my $b = Games::Boggle::Board->new; $template->param( board_string => $b->as_string ); my $board = build_board_array($b->as_string); $template->param( board => $board ); } print header, $template->output(); # ++ to merlyn sub build_board_array { my @board = split //, shift; s/Q/Qu/ foreach @board; @board = map { +{ line => [map +{ letter => $_ }, splice @board, 0, 4 ]}; } 1..4; return \@board; }

In reply to perl/cgi Boggle by ajdelore

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.