I need help with an 'if statement' in perl

S

Sam

I have a .cgi script on my website and (I think) it's written in perl.
I know some c++ and as far as I can tell this is the drop down menu
on my store.cgi page:
</ul>
<!-- VF begin client add search params form -->
<form action="$script_url" method="post">
List by Collection<br>
<select name="collection"><option>Select</option>|;

@collections=&get_collections;
foreach $collection (@collections) {print
"<option>$collection</option>";}

print qq | </select>
<input type="submit" value="Search">

I have a list of items categorized by collection. One of these is
simply called 'collection' (where as the others have names like
'ceramic collection', 'glassware collection', etc.).

*What I need to do is have the drop down menu list all of these
categories, and for the group that is simply called 'collection', I'd
like it to display 'Ken Edwards collection'. For example:

change
____________________________ that's the
Ceramic collection |\/| <-down arrow on the drop down menu
Figurine collection |
Collection | *This line needs to change
Glassware collection________|

to
____________________________
Ceramic collection |\/|
Figurine collection |
Ken edwards collection | *This line needs to change
Glassware collection________|

I assume this can be done with an if statement, but I can't do it.

Thanks in advance

PS:I sell Mexican crafts, and I'm looking for reciprocal links, if
your interested please email me. I wont plug myself here, but I'll
email you my website if youd like.

Thanks again

Sam
 
B

Ben Morrow

Quoth (e-mail address removed) (Sam):
I have a list of items categorized by collection. One of these is
simply called 'collection' (where as the others have names like
'ceramic collection', 'glassware collection', etc.).

*What I need to do is have the drop down menu list all of these
categories, and for the group that is simply called 'collection', I'd
like it to display 'Ken Edwards collection'.

@collections=&get_collections;

You don't need the '&' on that sub call; in fact, it may do things
you're not expecting.
foreach $collection (@collections) {print
"<option>$collection</option>";}

print '<option>',
(/^collection$/i ? 'Ken Edwards collection' : $_),
'</option>'
for @collections;

Note that this is a Very Bad Idea: the right answer is to fix whatever
is causing this collection to have the wrong name in the first place.

Ben
 
S

Sam

Thanks Ben,

This is the only time I will need to display the name of the
collection. Is this solution buggy. Why is it a very bad idea.

Thanks again
Sam
 
B

Ben Morrow

[please quote properly]

Quoth (e-mail address removed) (Sam):
This is the only time I will need to display the name of the
collection. Is this solution buggy. Why is it a very bad idea.

It is a bad idea because it is not maintainable: if you're not careful
you'll end up with hundreds of these special-case replacements all over
the code, and you'll have no idea which values come from where. You say
this is the only place you need the name; you cannot be certain there
will not be others in the future. As I said, the right answer is to
change get_collections to return the correct data.

Ben
 
S

Sam

I'm having trouble implementing this, where do I put the if
statement?(to Ben: Thanks for all the help. I named that one
'collection' because I need it to display as simply 'collection'
everywhere else, this really is the exception.)



Ben Morrow said:
[please quote properly]

Quoth (e-mail address removed) (Sam):
This is the only time I will need to display the name of the
collection. Is this solution buggy. Why is it a very bad idea.

It is a bad idea because it is not maintainable: if you're not careful
you'll end up with hundreds of these special-case replacements all over
the code, and you'll have no idea which values come from where. You say
this is the only place you need the name; you cannot be certain there
will not be others in the future. As I said, the right answer is to
change get_collections to return the correct data.

Ben
 
M

Malcolm Dew-Jones

Sam ([email protected]) wrote:
: I have a .cgi script on my website and (I think) it's written in perl.
: I know some c++ and as far as I can tell this is the drop down menu
: on my store.cgi page:
: </ul>
: <!-- VF begin client add search params form -->
: <form action="$script_url" method="post">
: List by Collection<br>
: <select name="collection"><option>Select</option>|;

: @collections=&get_collections;
: foreach $collection (@collections) {print
: "<option>$collection</option>";}


(why am i doing this?) untested

foreach $collection (@collections)
{
if ( $collection =~ m/^Collection$/ )
{
print "<option>Ken edwards collection</option>";
}else
{
print "<option>$collection</option>";
}
}




: print qq | </select>
: <input type="submit" value="Search">

: I have a list of items categorized by collection. One of these is
: simply called 'collection' (where as the others have names like
: 'ceramic collection', 'glassware collection', etc.).

: *What I need to do is have the drop down menu list all of these
: categories, and for the group that is simply called 'collection', I'd
: like it to display 'Ken Edwards collection'. For example:

: change
: ____________________________ that's the
: Ceramic collection |\/| <-down arrow on the drop down menu
: Figurine collection |
: Collection | *This line needs to change
: Glassware collection________|

: to
: ____________________________
: Ceramic collection |\/|
: Figurine collection |
: Ken edwards collection | *This line needs to change
: Glassware collection________|

: I assume this can be done with an if statement, but I can't do it.

: Thanks in advance

: PS:I sell Mexican crafts, and I'm looking for reciprocal links, if
: your interested please email me. I wont plug myself here, but I'll
: email you my website if youd like.

: Thanks again

: Sam
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top