[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Omaha.pm] CGI.pm is your friend



On Oct 15, 2007, at 9:05 PM, Daniel Linder wrote:
print $q->popup_menu(-name=>'month', -values=>[undef, 1..12]);

So, if I read this right, the 'magic' happens because of the []'s, right?

Not sure if any of it's magic, it's just tighter code than writing your own loops to generate HTML.

Does this end up calling the "popup_menu" function 13 times (undef, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, and 12)? Or does the [] do other stuff when
called inside that function?

popup_menu() is only called one time. It is handed an anonymous hash with two keys ("name" and "values"). The value of the "values" key is an anonymous array with the elements you listed in it.

Did that answer your question? Nothing magical, just a hash with an array in it.

If you don't do any web programming, this web stuff is pretty obtuse. But when generating gobs of HTML it's nice to call popup_menu() instead of having to do your own ugly looping.

http://search.cpan.org/~lds/CGI.pm-3.29/CGI.pm#CREATING_A_POPUP_MENU

$ cat j.pl
use CGI;
my $q = new CGI;
print $q->popup_menu(-name=>'month', -values=>[undef, 1..12]);

$ perl j.pl
<select name="month">
<option value=""></option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>

Dan

(Just an old functional programmer trying to wrap his head around the
object-oriented programming paradigm...)

Join the club. I'll print up some t-shirts.   :)

j