in reply to Re: Wierd bugs I would have never expected
in thread Wierd bugs I would have never expected
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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Wierd bugs I would have never expected
by Anonyrnous Monk (Hermit) on Dec 16, 2010 at 15:02 UTC | |
by ELISHEVA (Prior) on Dec 16, 2010 at 15:31 UTC | |
by jdporter (Paladin) on Dec 16, 2010 at 16:12 UTC | |
by ELISHEVA (Prior) on Dec 16, 2010 at 16:27 UTC | |
by Anonyrnous Monk (Hermit) on Dec 16, 2010 at 16:48 UTC |