[Israel.pm] local not local?

Shmuel Fomberg semuelf at 012.net.il
Thu Dec 7 09:36:56 PST 2006

Hello There.

I was extending Chart::Lines, and tried the following:

sub _draw_y_grid_lines
      no strict;
      local *Chart::Lines::_color_role_to_index = sub{return gdStyled};

The idea was that the _draw_y_grid_lines in the base class calls
_color_role_to_index to get the color. I wanted to temporarly override
it and force a value. 
Well, it did. However, I expected that after the function's end, the
function will return to normal. It didn't. all the colors where a huge
mass. :-(

I made a sample program, and the problem didn't show. Any idea?

(I solved the problem by extending _color_role_to_index too, and made a
switch. But that's not evil. :-) )


------ Start sample
sub one { return "one" }
sub two { return "two" }
sub answer {
    print "The answer is: ", one(), "\n";

#    local *one = \&two;
    local *one = sub {return "three"};
------ End

More information about the Perl mailing list