[SP-pm] Golf, mais complicado...
Igor Sutton Lopes
igor.sutton em gmail.com
Quarta Maio 9 07:09:34 PDT 2007
Oi Champs,
On May 9, 2007, at 7:09 AM, Luis Motta Campos wrote:
> Gente, eu estou tentando receber dois parâmetros via name-value
> syntax, transformar isso num hash e retornar apenas o que interessa.
> Acabei escrevendo isso:
>
> package Class;
> sub new {
> my $class = shift;
> ( $driver, $options ) = do{ my %args = @_; @args{qw/Driver
> DriverOptions/}; };
> }
>
> espero que o programador chame new() assim:
>
> package main;
> Class->new( Driver => $driver, DriverOptions => $options );
>
> Alguém consegue encurtar a linha com o do{}, sem perder clareza?
Que tal:
sub new {
my ($class, %params) = @_;
my ($driver, $options) = $params{Driver}, $params{DriverOptions};
}
Boa sorte!
--
Igor Sutton
igor.sutton em gmail.com
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: http://mail.pm.org/pipermail/saopaulo-pm/attachments/20070509/8fb09527/attachment-0003.html
-------------- Próxima Parte ----------
Um anexo não texto foi limpo...
Nome : PGP.sig
Tipo : application/pgp-signature
Tam : 186 bytes
Descr.: This is a digitally signed message part
Url : http://mail.pm.org/pipermail/saopaulo-pm/attachments/20070509/8fb09527/attachment-0003.bin
Mais detalhes sobre a lista de discussão SaoPaulo-pm