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?


In reply to Really Odd Bug With LWP and Device::SerialPort by kschwab

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.