Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
All I did was ask a simple question after RTFM, and after trying several different things, and after using SuperSearch. I'm not an idiot, nor am I lazy.

BUT, to humor you, from perlfaq4:

use FreezeThaw qw(cmpStr cmpStrHard); %a = %b = ( "this" => "that", "extra" => [ "more", "stuff" ] ); $a{EXTRA} = \%b; $b{EXTRA} = \%a; printf "a and b contain %s hashes\n", cmpStr(\%a, \%b) == 0 ? "the same" : "different"; printf "a and b contain %s hashes\n", cmpStrHard(\%a, \%b) == 0 ? "the same" : "different"; The first reports that both those the hashes contain the same data, while the second reports that they do not. Which you prefer is left as an exercise to the reader.

So yeah, it ought to be really simple. But if that is the case, shouldn't I be able to make the test fail when the two hashes are different?

Another thing I'm curious about: I mentioned that the test unexpectedly succeeded. There really isn't anything interesting when that happens. What information should I have provided?

In any event, I've actually tracked down the problem. There were two:

  1. Despite the verbage in perlfaq4, cmpStr and cmpStrHard return the same thing on success/failure. I'm not sure what the difference is supposed to be between these two functions.
  2. I was not actually setting the two hashes to be equal, so my results never changed because the test was always 'failing'. So even when I thought I was inverting the behavior, I wasn't. Also, I'm going to have to use is() instead of ok() since I expect 0. Data::Dumper++ for helping me find the bug in the actual code being tested. (Which, I suppose, was the original point.)

So PodMaster-- for posting and not actually helping. All I needed was confirmation that I was using FreezeThaw correctly. Too bad you couldn't do that, or at least keep silent.

Anyway, here's the only thing I had to change to the original code. Instead of the ok() line I used:

is( cmpStrHard(\%crosslinks, \%crosslinkscorrect), '0', "cmpStrHard" );

So the test now does the right thing. Now I just have to make sure ReadCrossLinks() does the right thing...

--J

Update: Added working version of the code to the bottom of this reply node.

Update 2: The confusion for me was in the text from perlfaq4 that says The first reports that both those the hashes contain the same data, while the second reports that they do not. This let me to believe that cmpStr was not cmpStrHard, and that perhaps there was a typo in the code example. Only after I understood what the two functions do did the phrase make sense.

But that's backwards. The docs are supposed to help me understand the functions, not prove my understanding after the fact. FreezeThaw wasn't any better, since it's highly geared toward OO programming (of which I admit to knowing little).

I think the text in perlfaq4 would read better as:

The first reports that the hashes %a and %b shown contain the same data, while the second reports that they are different, since $a{EXTRA} and $b{EXTRA} point to the same data, but are not equal to each other.

(This assumes that I know what I'm talking about, of course, but I think that's correct.) A little wordier, but much clearer, IMvHO.


In reply to Re^2: Using FreezeThaw correctly? by Rhys
in thread Using FreezeThaw correctly? by Rhys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 16:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found