On 10/25/06, Adriano Rodrigues <[EMAIL PROTECTED]> wrote:
On 10/25/06, Mug <[EMAIL PROTECTED]> wrote:
> I actually want to write a piece of code like that :
>
> my %u_info = user_detail ( $ENV{QUERY_STRING} );
> # I have $u_info{id} = 'foo' , $u_info{pass} = 12345
>
> my @attribs = user_detail ( $ENV{QUERY_STRING} );
> # I have @attribs = ( 'foo', 12345 );
>
> while I am asking %u_info , the user_detail will return a hash ,
> and while I am asking @attribs, I got an array return.
>

It cannot be done with the bare Perl interpreter, which only
recognizes scalar, list and void context. In your case, both %u_info =
and @attribs = call for a list context and that's all.

But you may try the CPAN module Want.

http://search.cpan.org/dist/Want


To tell the truth, it would be less subtle if you changed your
function so that an explicit param would tell Perl and also the ones
reading your code that a hash or a list would be returned.

  my %u_info = user_detail ( $ENV{QUERY_STRING}, return_type => 'hash' );
  # I have $u_info{id} = 'foo' , $u_info{pass} = 12345

  my @attribs = user_detail ( $ENV{QUERY_STRING}, return_type => 'list' );
  # I have @attribs = ( 'foo', 12345 );

With this change, you won't have dependencies to a module like 'Want'
that requires complilation.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to