#!//usr/pkg/bin/perl -w
use strict;
use warnings;
 
use CGI::Carp qw(fatalsToBrowser);
use CGI qw/:standard/;

my $qu = new CGI;
my $fortune = '/usr/pkg/games/fortune';
my $fortuneargs = '';

my @p = $qu->param;
$fortuneargs = join(' ', map { sprintf '-%s "%s"', $_, $qu->param($_) } @p );

print $qu->header,
      $qu->start_html( -title => 'fortune cookie' ),
      html_content(),
      $qu->end_html, "\n";

sub html_content
{
    open F, "$fortune $fortuneargs |" or return "<b>failed: $!</b>";
    return join('<br>',<F>);
}
