When I run the above, I get reams and reams of

Use of uninitialized value in exists at C:\test\632320.pl line 161. Use of uninitialized value in null operation at C:\test\632320.pl line + 161. Use of uninitialized value in hash element at C:\test\632320.pl line 1 +67. Use of uninitialized value in hash element at C:\test\632320.pl line 1 +67. Use of uninitialized value in hash element at C:\test\632320.pl line 1 +67. Use of uninitialized value in hash element at C:\test\632320.pl line 1 +67. Use of uninitialized value in exists at C:\test\632320.pl line 161. ...

It's not at all clear to me what a 'null operation' is, (I don't think I ever encountered that one before :), but the main problem appears to be that your code is still displaying signs of its no strict; heritage.

Specifically, within your compare sub, you have the loop iterator declared ahead of the first loop:

my $k; foreach $k ( keys %{ $hrefA } ) {

which is rarely better than declaring it in line, but is sometimes necessary if you wish to retain its value beyond the end of the loop.

However, in the next loop, which is only entered if you found whatever you are looking for in the first, you have no loop iterator variable, but do not appear to use $_ anywhere within it?

And the first thing you do within that second loop is test if the value of $k exists as a key within $hrefA.

if ($result) { foreach (keys(%{$hrefB})) { ## No loop variable if ( exists $hrefA->{$k} ) { ## line 161

But, as the value of $k is being retained from the first loop where it is explicitly looping over the keys of $hrefA (as shown above), then that test would appear to be redundant.

Except, the undefined warning for line 161 relates to the fact that somehow you are reaching this line with $k undefined.

My best guess, without having tried to work my way through and understand everything you are doing, is that your second loop is meant to be iterating the keys of $hrefB and checking whether they exist in $hrefA, and that if you replaced those two snippets with;

## my $k; foreach my $k ( keys %{ $hrefA } ) { ... if ($result) { foreach my $k (keys(%{$hrefB})) { ## No loop variable if ( exists $hrefA->{$k} ) { ## line 161

That might eliminate a large number of the warnings, and might also get you closer to making your code do what you are expecting.

Until you eliminate all the warnings your code is producing, it is impossible (or at least, asking a lot) for us to see symptoms of the problem you describe and so attempt to help you solve that problem.

I don't insist on use strict; use warnings; although I always use them myself, but in this case, it is very obvious that your code is not doing what you think it is doing, and if you had them enabled, you would have realised it yourself.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re^3: multi-threaded win32::console by BrowserUk
in thread multi-threaded win32::console by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.