#! /usr/bin/perl use strict; use warnings; use CGI; my @sizes = (0,500,750,1200); my @prices = (10,9.5,8.75); my $per_units = 50; my $total = '0.00'; my $q = CGI->new(); print $q->header; print $q->start_html(-style => 'this.css'); if ($q->param('feet') and $q->param('feet') =~ /^\d+$/) { if ($q->param('feet') > $sizes[$#sizes]) { query_us(); } else { calc_total($q->param('feet')); total_form($q->param('feet')); } } else { if ($q->param('feet') and $q->param('feet') =~ /^\d+\.\d+$/) { calc_total(int $q->param('feet')); total_form(int $q->param('feet')); } else { total_form(); } } print $q->end_html; sub calc_total { my ($feet) = @_; for my $i (0..$#sizes-1) { if ($feet > $sizes[$i] and $feet <= $sizes[$i+1]) { $total = ($feet / $per_units) * $prices[$i]; } } } sub total_form { my ($feet) = @_; $feet = 0 if !$feet; print $q->start_form; print '', '', '', '', '', '', '', '', '', '', '', '', '', '
Total Amount Of Footage ftTotal Cost
', '', '£'.$total.'
extra copies£10 each
minimum charge£50
'; print $q->end_form; } sub query_us { print "over 1200"; }