monkfan has asked for the wisdom of the Perl Monks concerning the following question:
Now I have a perl script that does the computation. Typically it is executed in command line like this.#!/usr/bin/perl -w use CGI ':standard'; print header, start_html('Order Ice Cream with Price'), h1('Order Ice Cream with Price'); generate_form(); print_results() if param(); print end_html(); sub print_results { my @top = param('toppings'); print b('Customer name: '), param('customer'), br, "You ordered ", param('no_unit'), ' unit of ', param('cone'), ' cone.'; print br; # how to include the perl script "compute_price.pl" result here? print ('Total price is ...'); } sub generate_form { print hr, start_form, strong('Your name : '), textfield( -name => 'customer' ), br,br strong('Cone: '), radio_group( -name => 'cone', -multiple => 1, -values => [qw/sugar waffle/]),br,br strong('Number of Units: '), textfield( -name => 'no_unit'), br,br submit( -value => 'Send Order' ), end_form, hr; }
The perl script can be found below:$ perl compute_price.pl -type sugar -unit 3
#!/usr/bin/perl -w use strict; use Data::Dumper; use Carp; use Getopt::Long; my $cone_type = 'sugar'; my $no_unit = 1; my $help = 0; if ( @ARGV == 0 ) { &usage(); exit(1); } my $res = GetOptions ( "type=s"=>\$cone_type, "unit=i"=>\$no_unit, "help"=>\$help,); if ($res) { die "Unit too large\n" if ($no_unit > 5); my %unitprice = ( 'sugar' => 100, 'waffle' => 200 ); my $total_price = $unitprice{$cone_type} * $no_unit; print "$total_price\n"; } sub usage { print <<HELP; Usage: perl $0 [-options] -h Print this help -type Cone type -unit No of Unit HELP exit; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Howto include Perl Script into CGI script
by BerntB (Deacon) on May 17, 2006 at 09:17 UTC | |
by monkfan (Curate) on May 17, 2006 at 09:37 UTC | |
by BerntB (Deacon) on May 17, 2006 at 09:45 UTC | |
by monkfan (Curate) on May 17, 2006 at 13:28 UTC | |
by wfsp (Abbot) on May 17, 2006 at 14:15 UTC | |
| |
|
Re: Howto include Perl Script into CGI script
by blazar (Canon) on May 17, 2006 at 09:41 UTC |