freddo411 has asked for the wisdom of the Perl Monks concerning the following question:

Simple Syntax question -- I think.

This syntax works,

my %d = ( '1' => "expire_date", '2' => "submit_date", ); my @a = sort(keys(%d)) ; my $date_dd_str = CGI::popup_menu( -name => 'date_name', -values => \@a, -labels => \%d );

but, trying to this syntax gives an error:

my %d = ( '1' => "expire_date", '2' => "submit_date", ); my $date_dd_str = CGI::popup_menu( -name => 'date_name', -values => \sort(keys(%d)), -labels => \%d );

Can someone enlighten me on what I'm doing wrong?

How, syntactically, do I provide array syntax and then grab a reference to the result? (I think I said that right).

-------------------------------------
Nothing is too wonderful to be true
-- Michael Faraday

Replies are listed 'Best First'.
Re: Simple Array Syntax question
by Fletch (Bishop) on May 19, 2004 at 20:41 UTC

    Why it doesn't work: sort returns a list, not an array. To get an arrayref you've got to use the anonymous arrayref constructor as was previously mentioned.

      Thanks for the explaination

      -------------------------------------
      Nothing is too wonderful to be true
      -- Michael Faraday

Re: Simple Array Syntax question
by dave_the_m (Monsignor) on May 19, 2004 at 20:34 UTC
Re: Simple Array Syntax question
by Plankton (Vicar) on May 19, 2004 at 20:41 UTC
    My guess ...
    -values => \sort(keys(%d)),
    ... should be ...
    -values => [sort(keys(%d))],

    Plankton: 1% Evil, 99% Hot Gas.