Perl-解析URL以获取GET参数值 [英] Perl - Parse URL to get a GET Parameter Value
问题描述
如何使用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::URL
或URI
来完成(我知道第一个已经过时了).预先感谢.
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屋!