Originally Posted by
WW
Code:
# parse_url_opts.py
def parse_url_opts(str):
(url,opts_str) = str.split("?")
opts_list = opts_str.split("&")
opts_pairs = [s.split("=") for s in opts_list]
return dict(opts_pairs)
the Perl version:
Code:
sub parse_url_opts {
my $url = shift;
(my $base, my $opts) = split /\?/, $url;
my @opt_list = split /&/, $opts;
my %opt_pairs = map { split /=/, $_ } @opt_list;
return %opt_pairs;
}
the only real difference is how the subroutines get their arguments and in Perl, the map is explicit.
Bookmarks