This is my first attempt at making a perl script of my own and hence would really appreciate any help with it. I have a form
[domain2trade.com...] which has questions with between one and five different answers for each question. These answers are given by clicking a radio button. The radio buttons have each been given a numerical value but not all will be selected and obviously it is unknown which ones they will bew.
I want to multiply an initial value by all the chosen radio buttons given numerical values by each other and print the result.
I've had a go but it doesn't work - Server 500 error - and if anyone can see where I am going wrong it would be REALLY APPRECIATED!
Thanks in advance
#!/usr/bin/perl
##########################################################
#This script is copyright 2001 of Roland Satchell
#No unauthourised use of this script
#contact us at admin@domain2trade.com
##########################################################
#initial value
$initial="3000000";
#currency exchange rate
$dollar="1.6";
$pound="1";
$frank="10.38";
$euro="1.49";
$mark="3.1";
$rupee="69.34";
$lira="3063";
#Define currency form inputs
$currency="dollar";
$currency="pond";
$currency="frank";
$currency="euro";
$currency="mark";
$currency="rupee";
$currency="lira";
#
#extension factor
$com="1";
$net="0.25";
$org="0.11";
$couk="0.18";
$extoth="0.1";
#define extension
$extension="com";
$extension="net";
$extension="couk";
$extension="org";
$extension="extoth";
#
#length factor
$lengfour="1";
$lengnine="0.7";
$lengten="0.5";
$lengfourt="0.3";
#define length
$length="lengfour";
$length="lengnine";
$length="lengten";
$length="lengfourt";
#
#hyphen factor
$hyphen="1";
$hyphen1="0.4";
$hyphentwo="0.15";
$hyphenthree="0.1";
#define hyphen
$hyph="hyphen";
$hyph="hyphen1";
$hyph="hyphentwo";
$hyph="hyphenthree";
#
#abreviation factor
$abrevno="1";
$abrevyes="0.35";
$abrevyespoor="0.18";
#define abreviation
$abrev="abrevno";
$abrev="abrevyes";
$abrev="abrevyespoor";
#
#spelling factor
$speone="1";
$spetwo="0.3";
$spethree="0.15";
$spefour="0.1";
#
#define spelling
$spell="speone";
$spell="spetwo";
$spell="spethree";
$spell="spefour";
#
#words factor
$oneword="1";
$twoword="0.65";
$threeword="0.35";
$fourword="0.22";
$fiveword="0.18";
#define words
$word="oneword";
$word="twoword";
$word="threeword";
$word="fourword";
$fiveword="fiveword";
#
#Commercial demand factor
$demone="1.4";
$demtwo="1.2";
$demthree="1.0";
$demfour="0.8";
$demfive="0.6";
#define demand
$demand="demone";
$demand="demtwo";
$demand="demthree";
$demand="demfour";
$demand="demfive";
#
#genericity factor
$genone="1";
$gentwo="0.5";
$genthree="0.13";
#define genericity
$generic="genone";
$generic="gentwo";
$generic="genthree";
#
#memorability
$memone="1";
$memtwo="0.7";
$memthree="0.5";
#define memorability
$mem="memone";
$mem="memtwo";
$mem="memthree";
#
#common word factor
$commone="1";
$commtwo="0.9";
$commthree="0.8";
$commfour="0.6";
$commfive="0.4";
#Define common word
$common="commone";;
$common="commtwo";
$common="commthree";
$common="commfour";
$common="commfive";
#
#Numbers contained in domain
$numone="0.35"
$numtwo="0.10"
#calculate sub1
$appraisetotal1="$initial*$currency*$extension*$length*$hyph*$abrev*$spell"
#calculate sub2
$appraisetotal2="$mem*$common*$word*$demand*$generic"
#calculate grand total
$appraisetotal="$appraisetotal1+$appraisetotal2"
#print results
print "<CENTER><H4>Your Domain Name $FORM{'domain'}</H4></CENTER>\n";
print "<CENTER><H4><Has an estimated Domain Value of $currency $appraisetotal</H4></CENTER>\n";
print "<p>\n";
I am by no means a perl expert but I'm sure that you will need to go with arrays for defining your variables and using data from the input form to specify which values you need out the array.
For example:
#Define currency form inputs
$currency="dollar";
$currency="pond";
$currency="frank";
$currency="euro";
$currency="mark";
$currency="rupee";
$currency="lira";
would be:
@currency=(dollar pond frank euro mark rupee lira);
and you would build the drop down in your form like so:
<select size="1" name="curr_selection">
<option value="0">dollar</option>
<option value="1">pond</option>
<option value="2">frank</option>
<option value="3">euro</option>
<option value="4">mark</option>
<option value="5">rupee</option>
<option value="6">lira</option>
</select>
and then in your equation you would use:
$appraisetotal1=$currency[$cur_select]*.....
Hang tight and our resident perl gurus will be along shortly to provide an answer that is far more useful than mine and will probably correct my methods as well;)
print "Content-type: text/html\n\n";
to the script.
You have a couple of semicolons missing. The first one is at line 167, After that, you'll need to remove the quotation marks from these two lines:
calculate sub1
$appraisetotal1="$initial*$currency*$extension*$length*$hyph*$abrev*$spell";
#calculate sub2
$appraisetotal2="$mem*$common*$word*$demand*$generic";
You will also need to have a form parcing sub routine. Here is one:
sub Parse_Form {
if ($ENV{'REQUEST_METHOD'} eq 'GET') {
@pairs = split(/&/, $ENV{'QUERY_STRING'});
} elsif ($ENV{'REQUEST_METHOD'} eq 'POST') {
read (STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
if ($ENV{'QUERY_STRING'}) {
@getpairs =split(/&/, $ENV{'QUERY_STRING'});
push(@pairs,@getpairs);
}
} else {
print "Content-type: text/html\n\n";
print "<P>Use Post or Get";
}
foreach $pair (@pairs) {
($key, $value) = split (/=/, $pair);
$key =~ tr/+/ /;
$key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~s/<!--(.¦\n)*-->//g;
if ($formdata{$key}) {
$formdata{$key} .= ", $value";
} else {
$formdata{$key} = $value;
}
}
}
$url = $formdata{'url'};
$user = $formdata{'user'};
$proxy = $formdata{'proxy'};
$use = $formdata{'use'};
This of course has to match the value of the html form.
#define words
$word="oneword";
$word="twoword";
$word="threeword";
$word="fourword";
$fiveword="fiveword";
#define spelling
$spell="speone";
$spell="spetwo";
$spell="spethree";
$spell="spefour";
You probably would want to use an array like Oil said. BTW, I'm no perl guru. Air and Brett are quite good, I have a feeling Dave may be too, though he is too modest to tell anyone.
So thanks once again and hopefully speak to you again.
P.S. littleman asked:
Could you tell us what you are trying to do with the define parts of the script?
For instance what are you trying to do in these parts?
#define words
$word="oneword";
$word="twoword";
$word="threeword";
$word="fourword";
$fiveword="fiveword";
#define spelling
$spell="speone";
$spell="spetwo";
$spell="spethree";
$spell="spefour";
I wanted to multiply all the chosen form inputs only and figured that if i did something like this it would let me say
$spell*$word*..... rather than $speone*threeword*... etc as i didn't know which ones would be chosen. I was making it up as i went along really and guessing so theres no supprise it was wrong.
The editor/debugger looks good and will help enourmously, thanks again.
Roly
#abreviation array
@tld=(1=Perfect 2=VeryGood 3=Good 4=Poor);
If my first option label on the form was:
1 = Perfect
would i write the array as:
@tld=(1_=_Perfect 2=VeryGood 3=Good 4=Poor);
Hope you can help. P.S. downloaded perl builder and that is a major help - thanks
Also, if you are going to be writing a lot of code , you should download perl onto your computer. Activestate has a download of perl with a bunch of goodies. Here is the
download page [activestate.com]. It also has documentation in html format.
p.s. sorry about the duplicate posts I keep hitting new topic as opposed to post reply