View Full Version : Perl Value Variable

09-24-2002, 09:08 PM

Wondering if anyone can point me in the correct direction. I have a Variable which is either 1 or 2. If the user selects 1. Then loads the next page. I want it to display certain txt different than if they choose 2. (using cgi Script)

In batch file it would be something like.

if exist 1 echo Hello 1
if exist 2 echo Hello 2.

I know its not the same, but may help in explaining what I am tring to do.

Any Ideas would be greatful as this is a show stopper at the moment.

09-25-2002, 09:49 AM

Have a look at the thread here (http://www.codingforums.com/showthread.php?s=&threadid=6555). In the beginning it, the requester was doing comparisons by numerical value (which is what you are asking to do) when they needed a comparison by string.

Their initial example code demonstrates exactly what you are asking for.

Hope this helps.

09-25-2002, 08:45 PM
mm no luck.

I`ll try and explain a little more what I want.

page 1 a user selects an option (i.e food)
That then goes as a hidden name food

Page 2

if user selected food then display this:- So you want food.

09-25-2002, 09:28 PM

I don't really understand what you mean, but the code required to compare a varible against a value:
$Var = 1;

if( $Var == 1 )
print "Var is one\n";
elsif( $Var == 2 )
print "Var is two\n";
print "Var is not one or two\n";
}If you need more help, then I thing that an example is in order or posting your existing code.

09-26-2002, 09:25 PM
No Luck I get the following displayed on the web site.

= 1; if( == 1 ) { print "Var is one "; } elsif( == 2 ) { print "Var is two "; } else { print "Var is not one or two "; }

The Code is very long to post (part of a shopping cart).
I have the following:-


or (depending on what option the user uses)


Therefore I would like the page to display if the Value=Nochex
Click here to be redirected to Nochex

If the value is Cheque.
I would like the page to display.

Details will be emailed to you.

Hope that makes it a bit clearer.
If you can help it would be great.

09-27-2002, 02:11 PM

To demonstrate this working, I have created the following PERL script:

use CGI qw(:standard);

print "Content-type: text/html\n\n";

$PayMethod = param('PAYME');
print <<EOF;
<body><select name="Method" onchange="window.location=('/cgi-bin/select.pl?PAYME='+this.options[this.selectedIndex].value)">
<option value="Other" >Other</option>
<option value="NoChex" >NoChex</option>
<option value="Cheque">Cheque</option>

if( $PayMethod eq "NoChex" )
print "NoChex method of payment was selected\<BR\>\n";
elsif( $PayMethod eq "Cheque" )
print "Cheque mehtod of payment was selected\<BR\>\n";

print <<EOF;

Try copying this sciprt into a file called select.pl in your cgi-bin directory. You may need to change the initial line to the correct path for your installation of PERL.

Initially the script provides you with a base page, when the drop down lick is changed, the script is recalled passing the PAYME parameter back. The value of PAYME is checked and the message is switched. There is no reason why this message should be a whole HTML page or a browser redirect message. Other processing, like the sending of an EMail can also be done.

I hope this helps.