J
John Ramsden
I have a program that calls functions in a module which
I also wrote, and have just wasted two hours chasing a bug
which turned out to be caused by a rogue 'foreach' loop
variable.
I was using a variable exported by the module as the loop
variable of a 'foreach' in the main program, and when a
function in the module was called by the main program,
from within the scope of the foreach, the variable of
the same name in the module had a different value! DUH!?
As soon as I changed the foreach to use a 'my' variable,
everything worked as I had expected.
Just thought I'd mention this strange feature, which seems
to me like a slight flaw (or bug?) in Perl - If variables
in another namespace cannot be used reliably as foreach
loop variables then 'use strict' should warn about this.
Cheers
John Ramsden
I also wrote, and have just wasted two hours chasing a bug
which turned out to be caused by a rogue 'foreach' loop
variable.
I was using a variable exported by the module as the loop
variable of a 'foreach' in the main program, and when a
function in the module was called by the main program,
from within the scope of the foreach, the variable of
the same name in the module had a different value! DUH!?
As soon as I changed the foreach to use a 'my' variable,
everything worked as I had expected.
Just thought I'd mention this strange feature, which seems
to me like a slight flaw (or bug?) in Perl - If variables
in another namespace cannot be used reliably as foreach
loop variables then 'use strict' should warn about this.
Cheers
John Ramsden