Hi.

I need a more efficient way of doing the task I am working on.
fields => { 'field1' => 'value', 'field2' => 'value', 'checkfield' => '1, 2, 3' }
The above code fails in WWW::Mechanize because you can't call a field and give it multiple values- I've tried that thinking it would work. I need a way to make checkfield work with multiple values so more than one checkbox is selected at once OR dynamically make the necessary checkfield fields to make it work. Yes, I posted this question a few days ago but I put more thought into this and I can get a solution to work but it's not clean or efficient.

In short: I have an array full of values that I need to inject into checkfield. I never know how many or what they are until runtime so a method of injecting multiple values at once ( 'checkfield' => '1, 2, 3' ) would be perfect! But since I couldn't get that to work I did..
@checks = (1, 3, 5); #just inserting some values my $cnt = 0; foreach (@checks) { $cnt++; } if ($cnt == 1) { fields => { 'field1' => 'value', 'field2' => 'value', 'checkfield' => '1' } } elsif ($cnt == 2) { fields => { 'field1' => 'value', 'field2' => 'value', 'checkfield' => '1', 'checkfield' => '3' } } elsif ($cnt == 3) { fields => { 'field1' => 'value', 'field2' => 'value', 'checkfield' => '1', 'checkfield' => '3', 'checkfield' => '5' } }
Like I said, this way works if I use array values but it's very ugly. Can someone help me make a more efficient solution?

In reply to help make code cleaner by Anonymous Monk

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.