<div dir="ltr">You can coerce everything into an arrayref like this (requires 5.10+):<br><div><br><span style="font-family:courier new,monospace">    my $foo = param 'foo';<br>    $foo = [ $foo // () ] if ref $foo ne 'ARRAY';<br>
</span></div><div><span style="font-family:courier new,monospace">    for (@$foo) { ... }</span><br></div><div><br></div><div>$foo is now an arrayref with 0, 1, or more elements. You're still checking for undef and arrayref, so this is just a convenient shortcut.<br>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Aug 21, 2014 at 3:55 AM, Andrew Beverley <span dir="ltr"><<a href="mailto:andy@andybev.com" target="_blank">andy@andybev.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi guys,<br>
<br>
I may be missing something here, so I wanted to run this by you:<br>
<br>
When a form is submitted that has multiple fields with the same name<br>
(such as several checkboxes), the values of that field are all returned<br>
in an array ref.<br>
<br>
However, if the same form is submitted, but only one value is returned<br>
(eg. only one checkbox has been ticked) then a scalar is returned. If no<br>
checkboxes are ticked, then undef is returned.<br>
<br>
This makes it difficult to process a form with several checkboxes, as<br>
the return value from param('checkbox') can be an array ref, scalar or<br>
undef, depending how many checkboxes are ticked.<br>
<br>
At the moment, I'm testing for each of those 3 conditions. Is there a<br>
better way?<br>
<br>
It would be useful if param() could be called in array context, in which<br>
case it would return 0, 1 or several items, depending on which ones were<br>
checked.<br>
<br>
Thanks,<br>
<br>
Andy<br>
<br>
<br>
_______________________________________________<br>
dancer-users mailing list<br>
<a href="mailto:dancer-users@dancer.pm">dancer-users@dancer.pm</a><br>
<a href="http://lists.preshweb.co.uk/mailman/listinfo/dancer-users" target="_blank">http://lists.preshweb.co.uk/mailman/listinfo/dancer-users</a><br>
</blockquote></div><br></div>