http://www.perlmonks.org?node_id=539298


in reply to Re: CGI.pm popup_menu labels bug?
in thread CGI.pm popup_menu labels bug?

Errto has got it, I think!
#!perl -w use CGI::Util qw(rearrange); sub showval { return defined($_[0])?$_[0]:"<undef>" } sub testcall { my (@p) = @_; my($name,$values,$default,$labels,$attributes,$override,$tabindex, +@other) = rearrange([NAME,[VALUES,VALUE],[DEFAULT,DEFAULTS],LABELS, ATTRIBUTES,[OVERRIDE,FORCE],TABINDEX],@p); print "name = ", showval($name), "\n"; print "values = ", showval($values), "\n"; print "labels = ", showval($labels), "\n"; print "attributes = ", showval($attributes), "\n"; print "override = ", showval($override), "\n"; print "tabindex = ", showval($tabindex), "\n"; print "\@other = ", join(" ", @other), "\n"; } sub vooba { my @result = ("foo", "bar"); print "vooba: wantarray = ", wantarray, "\n"; return @result; } sub emptylist { my @result = (); return @result; } print "testcall1\n"; testcall( -name => "nameparm", -values => [ "array" ], -labels => "labels", -default => vooba(), ); print "\ntestcall2\n"; testcall( -name => "nameparm", -values => [ "array" ], -default => vooba(), -labels => "labels", ); print "\ntestcall3\n"; testcall( -name => "nameparm", -values => [ "array" ], -default => emptylist(), -labels => "labels", ); __END__
Output:
testcall1 vooba: wantarray = 1 name = nameparm values = ARRAY(0x225848) labels = labels attributes = <undef> override = <undef> tabindex = <undef> @other = bar testcall2 vooba: wantarray = 1 name = nameparm values = ARRAY(0x225848) labels = <undef> attributes = <undef> override = <undef> tabindex = <undef> @other = bar="-labels" testcall3 name = nameparm values = ARRAY(0x225848) labels = <undef> attributes = <undef> override = <undef> tabindex = <undef> @other =

Replies are listed 'Best First'.
Re^3: CGI.pm popup_menu labels bug?
by blogical (Pilgrim) on Mar 26, 2006 at 18:38 UTC
    Dead on guys. *sigh* Fixed with a simple scalar($_[0]->value)

    "One is enough. If you are acquainted with the principle, what do you care for the myriad instances and applications?"
    - Henry David Thoreau, Walden