in reply to Compare URIs

This worked for me ...

use URI; use URI::QueryParam; use Data::Compare; my $uri1 = URI->new('/bob?joe=1&jack=2'); my $uri2 = URI->new('http://host/bob?jack=2&joe=1'); print "URI's are ", Compare( {map {($_ => $uri1->query_param($_))} $uri1->query_param}, {map {($_ => $uri2->query_param($_))} $uri2->query_param}, ) ? "" : "not ", "identical.\n" ;
The idea is to turn the URI's params into hash references via URI::QueryParam and map and compare them with Data::Compare. Assuming you only want to compare the params, of course. ;)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

Replies are listed 'Best First'.
Re^2: Compare URIs *params*
by Skeeve (Parson) on Oct 18, 2005 at 17:10 UTC

    I haven't installed that module, but could you please check what your program reporst for this inpu:

    my $uri1 = URI->new('/bob?joe=1&jack=2&jim=4&jim=3'); my $uri2 = URI->new('http://host/bob?jack=2&joe=1&jim=3&jim=4');

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

      Ahhhh ... throwing monkey wrenches into my code, are we? ;)

      This, of course, is not going to work, because you have a key collision with 'jim'. If you dump the hash refs out, you get something like:

      $VAR1 = { 'jack' => '2', 'joe' => '1', '3' => undef, 'jim' => '4' }; $VAR2 = { '4' => undef, 'jack' => '2', 'joe' => '1', 'jim' => '3' };
      I think there is a way to coerce URI::QueryParam into producing a data structure like so:
      $VAR1 = { 'jack' => '2', 'joe' => '1', 'jim' => ['3','4'] };
      but the point is growing moot, as halley pointed out and ikegami (and myself) how now discovered. :/

      jeffa

      L-LL-L--L-LL-L--L-LL-L--
      -R--R-RR-R--R-RR-R--R-RR
      B--B--B--B--B--B--B--B--
      H---H---H---H---H---H---
      (the triplet paradiddle with high-hat)