It's your return() statement. You've got
return (X) or (Y) which Perl reads as
(return(X)) or (Y), and since return() ALWAYS returns, you never get to the second clause. Rewrite it as
return ((X) or (Y)) or, in your specific case,
return X or Y.
And if you find any typos or errors otherwise in the article, please let me know. A problem I noticed looking at it right now is that the orcish maneuver should really be:
my $data_a = exists($cache{$a}) ? $cache{$a} : ($cache{$a} = mangle($a
+));
my $data_b = exists($cache{$b}) ? $cache{$b} : ($cache{$b} = mangle($b
+));
to allow for false and undefined values to be returned by mangle().