I haven't tried it but wouldn't URI and it canonical and eq methods work for you?
Update: Looks like URI will not normalize query params. Something like this should work (note, I did not check all cases - feel free to fix!)
!/usr/bin/perl -wd
use URI;
my $u1 = URI->new("http://www.perl.com/cgi-bin/script.cgi?a=b&c=d");
my $u2 = URI->new("http://www.perl.com/cgi-bin/script.cgi?c=d&a=b");
my $u1c = $u1->canonical;
my $u2c = $u2->canonical;
if( urlsEqual( $u1c, $u2c ) ) {
print "equal\n";
} else {
print "not equal\n";
}
sub urlsEqual {
my( $u1, $u2 ) = @_;
my( $q1, $q2 );
# First try URI eq
return 1
if( $u1->eq( $u2 ) );
# nope ... adjust query
$q1 = $u1->query();
$q2 = $u2->query();
$q1 = join( '&', sort( split( /[&;]/, $q1 ) ) )
if $q1;
$q2 = join( '&', sort( split( /[&;]/, $q2 ) ) )
if $q2;
$u1->query( $q1 );
$u2->query( $q2 );
return $u1->eq( $u2 );
}
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|