Perl-解析URL以获取GET参数值 [英] Perl - Parse URL to get a GET Parameter Value

查看:115
本文介绍了Perl-解析URL以获取GET参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用URI::URL Perl模块获取参数code的值?

How to get the value of a parameter code using URI::URL Perl module?

通过此链接:

http://www.someaddress.com/index.html ?test = value& code = INT_12345

可以使用URI::URLURI来完成(我知道第一个已经过时了).预先感谢.

It can be done using URI::URL or URI (I know the first one is kind of obsolete). Thanks in advance.

推荐答案

创建一个URI对象,并使用query_form方法获取查询的键/值对.如果您知道code参数仅指定一次,则可以这样操作:

Create a URI object and use the query_form method to get the key/value pairs for the query. If you know that the code parameter is only specified once, you can do it like this:

my $uri   = URI->new("http://www.someaddress.com/index.html?test=value&code=INT_12345");
my %query = $uri->query_form;

print $query{code};

或者,您可以使用URI :: QueryParam,它向URI对象添加了soem附加方法:

Alternatively you can use URI::QueryParam whichs adds soem aditional methods to the URI object:

my $uri = URI->new("http://www.someaddress.com/index.html?test=value&code=INT_12345");
print $uri->query_param("code");

这篇关于Perl-解析URL以获取GET参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆