Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Re: Really Odd Bug With LWP and Device::SerialPort

by runrig (Abbot)
on Aug 08, 2013 at 17:20 UTC ( #1048613=note: print w/replies, xml ) Need Help??

in reply to Really Odd Bug With LWP and Device::SerialPort

What version of perl? On 5.8.8, I get:
use strict; use warnings; my $url=''; use LWP::UserAgent; use Encode qw(is_utf8); use Data::Dumper; my $useragent = LWP::UserAgent->new(); my $request = new HTTP::Request; $request->method("GET"); $request->url($url); my $response = $useragent->request($request); my $data = $response->decoded_content(); print "1: ",is_utf8($data),"\n"; $data = substr($data,0); print "2: ",is_utf8($data),"\n"; # Prints: 1: 1 2:
On 5.14, I get:
1: 1 2: 1

Replies are listed 'Best First'.
Re^2: Really Odd Bug With LWP and Device::SerialPort
by kschwab (Priest) on Aug 08, 2013 at 18:02 UTC
    5.14.12 on the debian box, 5.16.2 on windows. My customer has the raspbian machine, so I'm not sure what version for them. On both machines above (which both show the bug), your code prints:
    1: 1 2: 1
    So, if the idea was that making the data non-utf8 was the cure, that doesn't seem to be it.

      Well, there is some differences in the 'MAGIC' attributes before and after the substr (no MAGIC before, but MAGIC after) when you do Devel::Peek::Dump($data), but I don't know enough about that stuff to know what it means (non-magic unicode strings don't work with serial ports?).

      This appears after the substr:

      MAGIC = 0x6336a0 MG_VIRTUAL = &PL_vtbl_utf8 MG_TYPE = PERL_MAGIC_utf8(w) MG_LEN = -1

      I would think that you might want to specify the encoding when writing to a serial port though.

      Update: Sounds somewhat similar to this issue?

        Going down that line, the bug isn't triggered when pulling from an http:// url, but it IS triggered with an https:// (ssl) url. The output from Devel::Peek::Dump looks pretty much identical. Which I suppose means the answer isn't anywhere in MAGIC or utf8. Thanks for the pointers though.
        # Devel::Peek::Dump output with https url (triggers bug) SV = PVMG(0x2fbcc3c) at 0x25e7ff4 REFCNT = 1 FLAGS = (PADMY,SMG,POK,pPOK,UTF8) IV = 0 NV = 0 PV = 0x2ff7034 "<!DOCT"\0 [UTF8 "<!DOCT"] CUR = 6 LEN = 12 MAGIC = 0x2f9066c MG_VIRTUAL = &PL_vtbl_mglob MG_TYPE = PERL_MAGIC_regex_global(g) MG_LEN = -1 # Devel::Peek::Dump output with http url (doesn't trigger bug) SV = PVMG(0x2e25434) at 0x2567ff4 REFCNT = 1 FLAGS = (PADMY,SMG,POK,pPOK,UTF8) IV = 0 NV = 0 PV = 0x2fe7c5c "<!DOCT"\0 [UTF8 "<!DOCT"] CUR = 6 LEN = 12 MAGIC = 0x2d96af4 MG_VIRTUAL = &PL_vtbl_mglob MG_TYPE = PERL_MAGIC_regex_global(g) MG_LEN = -1

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1048613]
LanX welcome to the twilight zone ...
[Eily]: LanX well since the onion is your eye you should see it everywhere
[marto]: sounds eye watering
[LanX]: oh your talking about my pic?
[Eily]: marto #SoSad
[holli]: duh
[marto]: I expect you to take a nice photo in Glasgow to replace this one :P
[Eily]: LanX yup, saw it when I checked your current rank
[LanX]: obviously the message is not clear enough if you only notice the onion now. ...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (14)
As of 2017-12-14 16:20 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (398 votes). Check out past polls.