Gossamer Forum
Home : General : Perl Programming :

Whats wrong with this if statement

Quote Reply
Whats wrong with this if statement
Hello,
I havn't a clue about perl really, but Im attempting to write a double if statement like the following:

Code:
if ($mycategory = "msm") {
$genderselection = "Men Seeking Men" and $gendervalue = "msm";}
else {
if ($mycategory = "msw") {
$genderselection = "Men Seeking Women" and $gendervalue = "msw";}}
else {
if ($mycategory = "wsm") {
$genderselection = "Women Seeking Men" and $gendervalue = "wsm";}}
else {
if ($mycategory = "wsw") {
$genderselection = "Women Seeking Women" and $gendervalue = "wsw";}}
The problem must be with the && which I assumed was used for AND.

Can anyone tell me how to properly write this statement,
If my category equals msw then gender selection equals men seeking women AND gendervalue equals msw otherwise if my category equals bla bla bla, you get the drift Im sure.

Would this be considered a nested if statement, and if so, how does one properly write it.

Thanks

Last edited by:

Bonus: Dec 15, 2001, 9:27 AM
Quote Reply
Re: [Bonus] Whats wrong with this if statement In reply to
Code:
if ($mycategory = "msm") {
$genderselection = "Men Seeking Men"; $gendervalue = "msm";}
elsif ($mycategory = "msw") {
$genderselection = "Men Seeking Women"; $gendervalue = "msw"; }
elsif ($mycategory = "wsm") {
$genderselection = "Women Seeking Men"; $gendervalue = "wsm";}
elsif ($mycategory = "wsw") {
$genderselection = "Women Seeking Women"; $gendervalue = "wsw";}}

Hopefully that will do what you want Tongue

I hope you can see what you were doing wrong Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Bonus] Whats wrong with this if statement In reply to
if
elsif
else

Is the standard control strucutre layout in Perl. Note that that is meant to be elsif there is no typo. This differes from the elseif in C.

Rgds

- wil
Quote Reply
Re: [Wil] Whats wrong with this if statement In reply to
Quote:
This differes from the elseif in C.

And PHP, as i found out after 2-3 hours of trying to work out why my statement wouldnt work...lol

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Whats wrong with this if statement In reply to
LOL!

What is it in PHP?

- wil
Quote Reply
Re: [Bonus] Whats wrong with this if statement In reply to
Hi Bonus,

There are a couple of problems. Firstly you are using:

if (something = 'value')

= is used to assign a value to something and is not intended to be used how you are using it.

You should use eq for comparing non-numeric strings and == for numeric.

The second problem is the way you are trying to assign two new values using and...try this:

Code:
if ($mycategory eq 'msm')
{
$genderselection = 'Men Seeking Men';
$gendervalue = 'msm'
}
elsif ($mycategory eq 'msw')
{
$genderselection = 'Men Seeking Women';
$gendervalue = 'msw'
}
elsif ($mycategory eq 'wsm')
{
$genderselection = 'Women Seeking Men';
$gendervalue eq 'wsm'
}
elsif ($mycategory eq 'wsw')
{
$genderselection = 'Women Seeking Women';
$gendervalue = 'wsw'
}
Quote Reply
Re: [PaulW] Whats wrong with this if statement In reply to
Paul, I missed the = (which should be eq), but you also have made a boo boo Wink (you forgot the ;'s at the end of some lines).

Bonus, try this;

Code:
if ($mycategory eq 'msm')
{
$genderselection = 'Men Seeking Men';
$gendervalue = 'msm';
}
elsif ($mycategory eq 'msw')
{
$genderselection = 'Men Seeking Women';
$gendervalue = 'msw';
}
elsif ($mycategory eq 'wsm')
{
$genderselection = 'Women Seeking Men';
$gendervalue eq 'wsm';
}
elsif ($mycategory eq 'wsw')
{
$genderselection = 'Women Seeking Women';
$gendervalue = 'wsw';
}

Just thought i would point it out Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] Whats wrong with this if statement In reply to
I knew someone was going to say that. Leaving off string terminators at the end of a block {} is perfectly valid. Try it Tongue

Last edited by:

PaulW: Dec 15, 2001, 11:32 AM
Quote Reply
Re: [PaulW] Whats wrong with this if statement In reply to
Ah well, i prefer to keep to the good habits, that way i dont make quite so many silly mistakes Tongue

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Post deleted by PaulW In reply to

Last edited by:

PaulW: Dec 15, 2001, 12:33 PM
Quote Reply
Re: [AndyNewby] Whats wrong with this if statement In reply to
Hmmm I was bored and found the quote:

Quote:
Every simple statement must be terminated with a semicolon, unless it is the final statement in a block, in which case the semicolon is optional.
Quote Reply
Re: [PaulW] Whats wrong with this if statement In reply to
Lol..you really must have been bored [;0]

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!