in reply to Re: Another Reason RTFMing Is A Good Thing
in thread Another Reason RTFMing Is A Good Thing

JavaFan,
Yes, it would have produced the same unexpected results but I would have also had to move:
my $hs = HTML::Strip->new();
higher in the file since I prefer to list all my subs at the bottom rather than the top of my file.

I am not sure I understand what you mean by (mis)using state. Is it not intended to ensure a variable is only initialized once? My expectation was that it was parsing from a clean state - primarily because I hadn't properly RTFMd - I didn't realize $hs was maintaining state.

I guess what you are saying is that in the end, after I realized what was going on I should have made the code more clear. I think adding a comment would suffice:

$hs->eof(); # ensure each call to parse() is from a clean slate

That is in fact what I intend and what the module offers to allow it. If I have completely misunderstood you, please clarify. If you just disagree then I note your objection but do not agree with your position.

Cheers - L~R

Replies are listed 'Best First'.
Re^3: Another Reason RTFMing Is A Good Thing
by JavaFan (Canon) on Oct 19, 2009 at 16:08 UTC
    I am not sure I understand what you mean by (mis)using state. Is it not intended to ensure a variable is only initialized once?
    Yes, in order to keep state. But your code obviously does not want to keep state. Just because you can call $hs->eof doesn't mean I would do that. Is HTML::Strip->new such an expensive call compared to $hs->eof that it's worthwhile to avoid calling it?
      JavaFan,
      Thank you. I now clearly see your point. Since this code is being written for a client who wants to understand all of the code, I will make it more clear. The client has also expressed a desire for optimizing for run time but I can show him how Benchmark works and let them decide for themselves (I suspect my way is marginally faster). Thanks again.

      Cheers - L~R