Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

case insensitive deep comparison

by KeighleHawk (Scribe)
on Jun 25, 2015 at 01:57 UTC ( #1131882=perlquestion: print w/replies, xml ) Need Help??

KeighleHawk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use Test::More and Test::Deep to compare two complex data structures (nested objects). Ideally, I would use cmp_deeply and pass it both data structures, but do a lower (or upper) case on all the values so the comparison would be case insensitive. Something like
return cmp_deeply( lc($Expected) , lc($AcTuaL) , "This is my case insensitive comparison" );
Am I missing something obvious here? I don't want to change the actual data in the structures. I also don't want to just stringify it because I want the diagnostics that come with Test::More to show what values actually fail. Ideas?

Replies are listed 'Best First'.
Re: case insensitive deep comparison
by robby_dobby (Friar) on Jun 25, 2015 at 03:16 UTC
Re: case insensitive deep comparison
by davido (Cardinal) on Jun 25, 2015 at 02:46 UTC

    cmp_deeply may be recursive, but lc isn't. I haven't used Test::Deeply enough to know if cmp_deeply has the ability to accept a comparator callback. If it could, that would make the solution pretty straightforward, but if it can, the documentation doesn't make it apparent. ...something like this would be great:

    my $result = cmp_deeply( $expected, $actual, sub { lc shift eq lc shift }, "This is a test using a callback to compare. );


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1131882]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2020-10-25 19:48 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (249 votes). Check out past polls.