Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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.fields => { 'field1' => 'value', 'field2' => 'value', 'checkfield' => '1, 2, 3' }
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?@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' } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: help make code cleaner
by Corion (Patriarch) on Mar 23, 2011 at 18:42 UTC | |
|
Re: help make code cleaner
by jethro (Monsignor) on Mar 23, 2011 at 18:57 UTC | |
|
Re: help make code cleaner
by Anonymous Monk on Mar 23, 2011 at 19:24 UTC |