Test for value of an array?

Hi All,

I have a cgi form that has several question I want filled out. Question 2 has multpile options and an 'other' text box. These options are listed as checkboxes. Users should can fill out as many as apply but they must at least fill out one checkbox or something in the 'other' input box.

<input type=checkbox name=q2_a value=myvalueA>
<input type=checkbox name=q2_b value=myvalueA>
<input type=checkbox name=q2_c value=myvalueA>
<input type=checkbox name=q2_d value=myvalueA>
<input type=text name=q2_other>

The data processing part of the script is grabs the params in the post and checks to see if there is any values passed from those params like so:

my $q2_a      = param('q2_a');
my $q2_b      = param('q2_b');
my $q2_c      = param('q2_c');
my $q2_d      = param('q2_d');
my $q2_other      = param('q2_other')

I load the variables into an array and do the test figuring that if there is no value in the array then the user must not have answered the question and then send them back.

my @q2test = ($q2_a, $q2_b, $q2_c, $q2_d, $q2_other);

if (@q2test eq "") {
            GetTemplate();
            print "You have left a required field blank. Please select an option from question    2.<br>";
            print "Please use the back button and try again. Thank You.";
            print"<p>Debug ~ Q2 Test: @q2test";
            EndTemplate();
      }
It's weird because if I test it and leave all the checkboxes empty and input box it does not throw the error even though the value of the array is nothing.  If I check something or fill out the text box then it passes fine but that doesn't get my goal accomplished.

Anyone have any thoughts? Is there a better way?  

All I want to do is make sure something is answered here. Kinda stumped and any help would be apreciated.

thanks!!
-mike

mookie13Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

cwpCommented:
If you use @q2test, it will return the number of elements in the array, so you're really comparing "8" with "".

You can try this instead of the @q2test:
   my $q2 = $q2_a || $q2_b || $q2_c || $q2_d || $q2_other;
   if ($q2 eq "") {
      print "Question 2 field blank\n";
   }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cwpCommented:
Correction: If you use @q2test *in a scalar context*. @q2test eq "" is scalar enough.
mookie13Author Commented:
Thank you so much CWP!!! It worked like a charm.
cwpCommented:
No problem. Not sure if you've noticed, but it's supposed to be 'comparing "5" with ""' as well... I guess 3am isn't a good time for me to answer questions ;).

Anyway, good luck with your program!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.