Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   I need help with an 'if statement' in perl (http://www.velocityreviews.com/forums/t886909-i-need-help-with-an-if-statement-in-perl.html)

Sam 06-16-2004 01:40 AM

I need help with an 'if statement' in perl
 
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

Ben Morrow 06-16-2004 01:53 AM

Re: I need help with an 'if statement' in perl
 

Quoth samuelvange@cox.net (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

--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |

Sam 06-17-2004 05:16 AM

Re: I need help with an 'if statement' in perl
 
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








Ben Morrow <usenet@morrow.me.uk> wrote in message news:<cao96b$ra2$2@wisteria.csv.warwick.ac.uk>...
> Quoth samuelvange@cox.net (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


Ben Morrow 06-17-2004 06:36 AM

Re: I need help with an 'if statement' in perl
 
[please quote properly]

Quoth samuelvange@cox.net (Sam):
> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<cao96b$ra2$2@wisteria.csv.warwick.ac.uk>...
> > Quoth samuelvange@cox.net (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.

>
> 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

--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk

Sam 06-18-2004 03:49 PM

Re: I need help with an 'if statement' in perl
 
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 <usenet@morrow.me.uk> wrote in message news:<care6b$683$1@wisteria.csv.warwick.ac.uk>...
> [please quote properly]
>
> Quoth samuelvange@cox.net (Sam):
> > Ben Morrow <usenet@morrow.me.uk> wrote in message news:<cao96b$ra2$2@wisteria.csv.warwick.ac.uk>...
> > > Quoth samuelvange@cox.net (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.

> >
> > 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


Malcolm Dew-Jones 06-18-2004 07:43 PM

Re: I need help with an 'if statement' in perl
 
Sam (samuelvange@cox.net) 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

--

(Paying) telecommute programming projects wanted. Simply reply to this.



All times are GMT. The time now is 09:53 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.