I need help with an 'if statement' in perl

Discussion in 'Perl Misc' started by Sam, Jun 16, 2004.

  1. Sam

    Sam Guest

    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
     
    Sam, Jun 16, 2004
    #1
    1. Advertisements

  2. Sam

    Ben Morrow Guest

    Quoth (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. |
    Musica vel ipsas arbores et horridas movet feras. |
     
    Ben Morrow, Jun 16, 2004
    #2
    1. Advertisements

  3. Sam

    Sam Guest

    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 <> wrote in message news:<cao96b$ra2$>...
    > Quoth (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
     
    Sam, Jun 17, 2004
    #3
  4. Sam

    Ben Morrow Guest

    [please quote properly]

    Quoth (Sam):
    > Ben Morrow <> wrote in message news:<cao96b$ra2$>...
    > > Quoth (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, Jun 17, 2004
    #4
  5. Sam

    Sam Guest

    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 <> wrote in message news:<care6b$683$>...
    > [please quote properly]
    >
    > Quoth (Sam):
    > > Ben Morrow <> wrote in message news:<cao96b$ra2$>...
    > > > Quoth (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
     
    Sam, Jun 18, 2004
    #5
  6. Sam () 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.
     
    Malcolm Dew-Jones, Jun 18, 2004
    #6
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    2,174
  2. Milsnips

    need help with an UPDATE statement

    Milsnips, Nov 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    326
    Karl Seguin
    Nov 15, 2005
  3. Davis Marques
    Replies:
    6
    Views:
    405
    Paul Rubin
    Jan 12, 2004
  4. Dmitry Teslenko
    Replies:
    2
    Views:
    289
    Dmitry Teslenko
    Dec 19, 2007
  5. Replies:
    1
    Views:
    142
    Anthony Eden
    Mar 9, 2007
  6. Steve Bishop

    Need Help with Else Statement

    Steve Bishop, Feb 1, 2004, in forum: Javascript
    Replies:
    1
    Views:
    149
    F. Da Costa
    Feb 1, 2004
  7. Replies:
    10
    Views:
    290
    Dr.Ruud
    Jun 27, 2006
  8. Anil A Kumar
    Replies:
    2
    Views:
    239
    J├╝rgen Exner
    Aug 3, 2011
Loading...