[Israel.pm] Strange variables puzzle

Yitzchak Scott-Thoennes sthoenna at efn.org
Thu Jan 3 01:51:59 PST 2008

On Wed, January 2, 2008 1:01 pm, Issac Goldstand wrote:
> I've run into an interesting puzzle.  The following code fragment:
> print "Ensuring that $url is in website ".$req->{baseurl}."...\n" if DEBUG
> >=2;
> print "OK1\n" if $url eq "http://jigsaw.w3.org/css-validator/"; print
> "OK2\n" if $req->{baseurl} eq "http://www.mirimar.net";
> if
> (URI->new("http://jigsaw.w3.org/css-validator/")->rel("http://www.mirimar
> .net")->eq("http://jigsaw.w3.org/css-validator/"))
> {print "BAD";} else {print "GOOD";}
> if (URI->new($url)->rel($req->{baseurl})->eq($url)) {print "BAD";} else
> {print "GOOD";}
> This has somehow managed to produce the following output:
> Ensuring that http://jigsaw.w3.org/css-validator/ is in website
> http://www.mirimar.net...
> OK1
> OK2
> Without any additional context can someone figure out how this *could*
> be possible (the URI functions are from the standard URI module, $url and
> $req->{baseurl} are passed in from another context which I can't
> change, DEBUG is 2)?

I'm guessing from your wording that you yourself solved the puzzle,
and that using ->eq("$url") fixes the problem.

The eq method considers an object of different class to be not equal,
even if it would have stringified the same, and apparently $url is
some class other than URI::http.

More information about the Perl mailing list