in reply to Re: Attempt to free unreferenced scalar...
in thread Attempt to free unreferenced scalar...

I was getting this bug today and none of the pages I read helped so I figured I should post now that I figured out the problem. All pages I read indicate it's probably a perl bug itself. But for me it was due to having a foreach loop like this:

foreach $key (keys %hash) {

}

with another foreach loop inside using the same variable name and same hash

foreach $key (keys %hash) {
   foreach $key (keys %hash) {

   }
}

Incidentally, this only caused the problem in strict mode. I'm not saying this simple loop would replicate the problem, I got it down to about 20 lines and still throwing the error. But if you're getting this error message, look for a nested thing like that, it might be what's causing it. Perl should maybe throw a warning when a loops are nested like that with the same variables, because otherwie it was pretty hard to track down in my 1000 line program, I had to remove piece by piece until it became evident.

  • Comment on Re^2: Attempt to free unreferenced scalar...