kschwab has asked for the wisdom of the Perl Monks concerning the following question:
I've found an odd bug / interaction between LWP and Device::SerialPort and/or Win32::SerialPort. I've also found a workaround, so the reason for the question is pure curiousity...and perhaps notifying the module owner of the issue if I can figure out what it is.
The issue, in short, is this:
If I take a scalar variable that was created using LWP::UserAgent's $req->decoded_content method, and pass it to Device::SerialPort as something to be written, I get:
Here's the really odd part.
If I "disassociate" the variable that came from LWP before passing it to Win32::SerialPort or Device::SerialPort, everything works great. No warnings, no corrupted data:
my $data = $response->decoded_content; # doing what should be a "no-op", below, makes the problem # dissappear. $data=substr($data,0);
Even more odd, other ways of "disassociating" the variable don't fix the problem.
# doesn't work $data=~/^(.*)$/; $data=$1;
# pass $newvar on instead of $data...doesn't work my $newvar=$data
Aside from $data=substr($data,0), the only other method that fixed the problem was writing the data to a file, and reading it back into a fresh new variable to pass to Device::SerialPort (and/or Win32::SerialPort).
Other oddities:
I did double-check myself by doing a hex dump of the contents in $data...nothing odd. Just a short text string like "THIS IS A TEST".
Any ideas on what this might be, and why $data=substr($data,0) would fix it when other methods don't?
|
|---|