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

[Omaha.pm] shorter is better 2



Another good one from yesterday:

 

BEFORE (string manipulation):

 

  my $uri=$self->uri();     # A URL scalar w/o arguments

  foreach my $param qw(InterfaceName) {

    if ( $args{$param} ) {

       $uri .= '?' . $param .  '=' . $args{$param};

    } elsif ( $uri_parameters->{InterfaceName} ) {

       $uri .= '?' . $param . '=' . $uri_parameters->{$param};

    }

  }

  foreach my $param qw(propertyName messageType transactionId status ) {

    if ( $args{$param} ) {

       $uri .= '&' . $param .  '=' . $args{$param};

    } elsif ( $uri_parameters->{InterfaceName} )  {

       $uri .= '&' . $param . '=' . $uri_parameters->{$param};

    }

  }

 

AFTER (use URI from CPAN):

 

  my $uri = URI->new($self->uri());

  $uri->query_form(%args, %$uri_parameters);

  $uri = $uri->as_string;

 

:)

 

j