Ing. Branislav Gerzo schreef:
> Dr.Ruud:
> thanks a lot Dr.Ruud (not Dr.Perl?:)). It works like a charm.
> I completely forget to [^morecharacters] idiom.
Your welcome. Some of my assumptions may proof to be not practible, but
I think the code is easy to adjust.
Know that there are better ways to split an URL.
Something like [^']*' can also be written as .*?', but here I like the
first format better.
A slightly leaner version:
#!/usr/bin/perl
use strict;
use warnings;
{
local ($,,$\) = ("\t", "\n");
my $orig = "
k='http://example.com/' F
k='http://example.com/#a' F
k='http://example.com/foo.php#a' F
k='http://example.com/foo.php?id=10&p=1#a' F
";
my $goal = "
k='http://example.com/?w=sk' F
k='http://example.com/?w=sk#a' F
k='http://example.com/foo.php?w=sk#a' F
k='http://example.com/foo.php?w=sk&id=10&p=1#a' F
";
my $work = $orig;
s~('http://example.com/ # any ? becomes &
[^?']*) #
\? #
([^']*') #
~$1&$2~gmx #
, s~('http://example.com/) # protocol + host
([^'#&]*) # path
([^'#]*) # parameters
([^']*') # anchor
~$1$2?w=sk$3$4~gmx # insert ?w=sk
for $work;
print $orig;
print $goal;
print $work;
print 'It works!' if ($work eq $goal);
}
--
Affijn, Ruud
"Gewoon is een tijger."
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>