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

Re^2: Using FreezeThaw correctly?

by Rhys (Pilgrim)
on Sep 21, 2004 at 00:55 UTC ( #392541=note: print w/ replies, xml ) Need Help??


in reply to Re: Using FreezeThaw correctly?
in thread Using FreezeThaw correctly?

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.


Comment on Re^2: Using FreezeThaw correctly?
Select or Download Code
Re^3: Using FreezeThaw correctly?
by PodMaster (Abbot) on Sep 21, 2004 at 04:45 UTC
    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.
    All I did was answer the question (using your own words no less) without calling you an idiot or lazy. I can't help if you feel like an idiot.
    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?
    But it is simple, and you can make the test fail, you just have to write it correctly. I thought that would be obvious once you understood how cmpStrHard works. ok( not cmpStrHard(\%crosslinks, \%crosslinkscorrect) );
    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?
    Something everyone can run that demonstrates your dilemma. Only you have access to JScan::ReadCrossLinks , ReadCrossLinks, \%crosslinks, \%options...
    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.
    I know I helped ( I showed you that you're not using FreezeThaw correctly). I wasn't very explicit and verbose, but i thought it was obvious. Too bad you didn't get it.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://392541]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2014-07-10 09:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (203 votes), past polls