|
[x]
Posted via EE Mobile
|
||
Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again. |
||
| 10/28/2009 at 05:00PM PDT, ID: 24853109 |
|
[x]
Attachment Details
|
||
|
[x]
The Solution Rating System
|
||
With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.
Your Input Matters If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support. Thank you! |
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: |
<!candle.html>
<HTML>
<HEAD><TITLE>Candles Unlimited</TITLE></HEAD>
<BODY>
<H1>Product Information</H1>
<FORM ACTION="http://yourservername/cgi-bin/chap09/c09ex5.cgi" METHOD=POST>
<P>Code: <INPUT TYPE=text NAME=Code></P>
<P>Name: <INPUT TYPE=text NAME=Name></P>
<P>Price: <INPUT TYPE=text NAME=Price></P>
<INPUT TYPE=submit Name=Button VALUE=Save>
<INPUT TYPE=submit Name=Button VALUE=Delete>
</FORM></BODY></HTML>
#!/usr/bin/perl
#c09ex5.cgi - saves data to and removes data from a database
print "Content-type: text/html\n\n";
use CGI qw(:standard);
use SDBM_File;
use Fcntl;
use strict;
use warnings;
use diagnostics;
use CGI;
use CGI::Carp 'fatalsToBrowser';
#declare variables
my ($code, $name, $price, $button);
#assign values to variables
$code = param('Code');
$name = param('Name');
$price = param('Price');
$button = param('Button');
($code, $name, $price) = format_input();
if ($button eq "Save") {
add();
}
elsif ($button eq "Delete") {
remove();
}
exit;
#****user-defined functions*****
sub format_input {
#declare and assign values to temporary variables
my ($c, $n, $p);
($c, $n, $p) = ($code, $name, $price);
#removes leading and trailing spaces
$c =~ s/^ +//;
$c =~ s/ +$//;
$n =~ s/^ +//;
$n =~ s/ +$//;
$p =~ s/^ +//;
$p =~ s/ +$//;
#removes dollar sign
$p =~ s/$//;
#change to upper case
$c =~ tr/a-z/A-Z/;
$n =~ tr/a-z/A-Z/;
return $c, $n, $p;
}
sub add {
#declare variable
my %product;
#open database, add record, close database
tie(%product, "SDBM_File", "chap09/c09ex5", O_CREAT|O_RDWR, 0666)
or die "Error opening chap09/c09ex5. $!, stopped";
$product{$code} = $name, $price;
untie(%product);
#create web page
print "<HTML>\n";
print "<HEAD><TITLE>Candles Unlimited</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1>Candles Unlimited</H1>\n";
print "The $name product has been added to the database.<BR>\n";
print "</BODY></HTML>\n";
}
sub remove {
#declare variables
my (%product, $msg, %dummy);
#open database
tie(%product, "SDBM_File", "chap09/c09ex5", O_RDWR, 0)
or die "Error opening chap09/c09ex5. $!, stopped";
#determine if information exists in database
%dummy = %product;
if (exists($dummy{$code})) {
delete($product{$code});
$msg = "The product has been deleted.";
}
else {
$msg = "Product is not in database.";
}
#close database
untie(%product);
#create web page
print "<HTML>\n";
print "<HEAD><TITLE>Candles Unlimited</TITLE></HEAD>\n";
print "<BODY>\n";
print "<H1>Candles Unlimited</H1>\n";
print "$msg\n";
print "</BODY></HTML>\n";
}
|
Advertisement