Thank you, but my problem is a bit more complex. I should try to explain better. 1) I have a form which contains a multichoice box in that format:
<select name="colors" multiple size=5 "> <option>Blue <option>Red <option>Yellow <option>Green </select>
2) When user fill out form, they can choose multiple options. After they submit, it saves the options into a flat text file, along with the other form's answer: userid|password|name|email|Blue,Red|comments 3) The user has the option to come back in later time and edit his info. It is prompted with an edit form on which his previous answers are already inserted. In this case I would need the edit form to present the "colors" field in this way:
<select name="colors" multiple size=5 "> <option selected>Blue <option selected>Red <option>Yellow <option>Green </select>
I am limited with perl and I have tried to basically read the array from the choice of colors: @colors = ("Blue","Red","Yellow","Green"); make the chosen colors scalar into an array and read it: @chosen = ("Blue","Red"); an then tried to compare both but all I can come up with is a bunch of nested foreach statements which is not good:
foreach colors { foreach chosen { if $chosen eq $color { $editchosen = <option selected>$color } else { $editchosen = <option>$color } } }
Anyway, you can tell that I am not starting well with my thinking. Help! Thank you.

In reply to Re: (cLive ;-)Re: nesting foreach statements by Ogmios
in thread nesting foreach statements by Ogmios

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.