This may be old news for seasoned module authors, but I just got bitten by a new bug I wasn't really aware of before.
While debugging a script using Mail::Audit::Attach, I was wondering why the script would die at a certain point (it called a method on an undefined value). Finally, I found out the reason. The code was something like this:
foreach (@attachments) { $_->method1; $_->method2; }
Unfortunately, method1 contained a loop using $_ and finally setting it to undef, thus causing the script to die on the next method call.
The funny thing is, I have used constructs like
{ local $/ = undef; $data = <FILE> }
a lot of times, but somehow the concept never transferred itself to $_.
The solution, of course, is to either not use $_, or insert
local $_
in each method/function that uses it.
update (broquaint): title clarification (s/clutter/clobber/)
In reply to Is your module clobbering predefined variables? by crenz
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |