At least as near as I can possibly see. It wouldn't be the first time I thought A was the issue when in fact B was. But I'm fairly certain. I narrowed it down by the old comment out code until nothing is left but the bare minimum to recreate the bug. The sample is pretty slim.

There are in fact two possible ways to make the bug go away. (a) add a printf within the sub that wants to use the $SOME_CLASS or (b) comment out the return 1. Plain old 1; ( no return) at the end of the file works fine. It is only when the word return is added. I'm not inclined to blame the bug on failing to have a printf in the sub since that doesn't seem to me to be a reasonable requirement of proper use of package my variables.

Here is the code that shows the problem. The test script:

use strict; use warnings; use Monks::Foo::ReturnInModule; weAreOffToSeeTheWizard();

The module Monks/Foo/ReturnInModule.pm:

use strict; use warnings; { package EmeraldCity; sub CLICKS { 2 }; } my $SOME_CLASS='EmeraldCity'; sub clickTheRubyShoes { my ($aData) = @_; # uncommenting this line also makes the problem go away #print STDERR "value of \$SOME_CLASS: $SOME_CLASS\n"; my $crClick = sub { my $iWhereWellGo = $aData->[$SOME_CLASS->CLICKS]; }; $crClick->(); print STDERR "Back in Kansas!\n"; return 1; } sub weAreOffToSeeTheWizard { print STDERR "value of \$SOME_CLASS: $SOME_CLASS\n"; clickTheRubyShoes(['So far away','Closer','Home']); return 1; } # there is NO warning or complaint about this "return 1" even # though it is outside a sub. # # with return 1 uncommented, # calling weAreOffToSeeTheWizard() results in # value of $SOME_CLASS: EmeraldCity # can't call method "CLICKS" on an undefined value at XXX line 14 # # with it commented out, and doing plain 1; to return we get # value of $SOME_CLASS: EmeraldCity # Back in Kansas! return 1; #1;

In reply to Re^2: Wierd bugs I would have never expected by ELISHEVA
in thread Wierd bugs I would have never expected by ELISHEVA

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.