Splitting URL into Patterns
am 13.07.2011 17:53:35 von AKINLEYE
--0016e6d27485497b4104a7f56b2e
Content-Type: text/plain; charset=ISO-8859-1
please I need to split a bunch of URL into their respective domain name
like abcd.com , it path direcory like /~bert/build/ , it's Argument
constitutent like uid =1
Take for example
msprogram.cn/update/ld.php?ld.php&id=1936&rs=1765405346&cc=0 &uid=1
I need the first match to be mspgroam.cn
The Directory to be /update/
The File should be ld.php
and argument should be a bunch of v=1 ,rs=1765405346 , cc=0 uid=1
I have tried replacing all the rules with a regular expression such as
$domain =~ s/[.]/<=>/g; # Substitute all values of . with <=
$domain =~ s/((?=(\w+|\d+))[?|&])/<=>/g ; # Substitute value with of word
starting with ? and ending with a & or space chomp has taken care of the
newlin
$domain =~ s/\//<=>/g;
running this 3 rule does not do the matching I am confused on how to go
about these .
Thanks for your wisdom
--
Akinleye Adedamola
--0016e6d27485497b4104a7f56b2e--
Re: Splitting URL into Patterns
am 13.07.2011 18:08:53 von Shlomi Fish
Hi Akinleye,
On Wed, 13 Jul 2011 16:53:35 +0100
AKINLEYE wrote:
> please I need to split a bunch of URL into their respective domain name
> like abcd.com , it path direcory like /~bert/build/ , it's Argument
> constitutent like uid =3D1
>=20
> Take for example
> msprogram.cn/update/ld.php?ld.php&id=3D1936&rs=3D1765405346& cc=3D0&uid=3D1
> I need the first match to be mspgroam.cn
> The Directory to be /update/
> The File should be ld.php
>=20
> and argument should be a bunch of v=3D1 ,rs=3D1765405346 , cc=3D0 uid=3D1
>=20
For parsing URLs please see:
http://beta.metacpan.org/release/URI
Please do not do it using regular expressions.
Regards,
Shlomi Fish
--=20
------------------------------------------------------------ -----
Shlomi Fish http://www.shlomifish.org/
"Humanity" - Parody of Modern Life - http://shlom.in/humanity
Real programmers donâ=99t write workarounds. They tell their users to =
upgrade
their software.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
Re: Splitting URL into Patterns
am 13.07.2011 18:15:32 von Jim Gibson
On 7/13/11 Wed Jul 13, 2011 8:53 AM, "AKINLEYE"
scribbled:
> please I need to split a bunch of URL into their respective domain name
> like abcd.com , it path direcory like /~bert/build/ , it's Argument
> constitutent like uid =1
>
> Take for example
> msprogram.cn/update/ld.php?ld.php&id=1936&rs=1765405346&cc=0 &uid=1
> I need the first match to be mspgroam.cn
> The Directory to be /update/
> The File should be ld.php
>
> and argument should be a bunch of v=1 ,rs=1765405346 , cc=0 uid=1
Parsing URLs and URIs is a common problem. When encountering a problem like
this that other people may have encountered before, your first thought
should be to search the CPAN repository at for an
appropriate module.
For example, a few minutes searching on the terms "URL" and "URI" revealed
the URI module, which may have exactly the functions you are looking for.
Example:
use URI;
my $uri = URI->new('http://msprogram.cn/update/ld.php?uid=1');
print $uri->host() . "\n";
Outputs:
msprogram.cn
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/