in reply to Re^2: Cannot access HTTP::Response content properly
in thread Cannot access HTTP::Response content properly

Extra tidbits:

Replies are listed 'Best First'.
Re^4: Cannot access HTTP::Response content properly
by Anonymous Monk on Nov 03, 2009 at 13:42 UTC

    Hello All, Thank you so far. I took all your suggestions (e.g. decoded_content(), file handles, variable declarations, etc). It turns out though, that my hunch was right. I should have done an "ls -l" on the file and I would have discovered it was not an empty file. If you hadn't figured out already I am on a Unix/Linux system. Contrary to my original posting I thought I had done a "cat" when in actuality I had done a "more". Funny enough, regardless of whether I decode the content or not, something shows up with the "cat" command but not the "more" command. Also, I am able to edit the file in "vi" and see something. I am still stumped by the output though. Assuming that I know the contents of my file should be two lines of text separated by a newline. For example, "The Cat" and "The Dog" on separate lines:

    If I "cat" the file, I get:

    The Cat
    The Dog

    If I "vi" the file, I get:

    @^T@^h@^e@^ @^C@^a@^t@^
    @^T@^h@^e@^ @^D@^o@^g@^ @^

    Just for giggles, I did an "od -c", and I got:

    0000000 \0 T \0 h \0 e \0 C \0 a \0 t \0 \n \0 T
    0000020 \0 h \0 e \0 D \0 o \0 g \0 \n

    So for the $64 million questions, why is this showing up empty when I "more" the file, why is the calling program seeing it as empty as does the "more" command, and what's with these characters?
      The file is encoded using UTF-16be
Re^4: Cannot access HTTP::Response content properly
by Anonymous Monk on Nov 03, 2009 at 15:17 UTC
    If I decode this with UTF8, should that not take care of it?
      • It's not UTF-8, it's UTF-16be (or subset UCS-2be). Treating UTF-16be as UTF-8 is a bug.

      • Output decoded text is a bug. If you decoded text, you need to encode it when you output it. You're free to use a different encoding, though.

        Ok, so then I need to encode my output to ascii text somehow. You'll have to excuse my ignorance here as this is totally uncharted territory for me. So would something like the following work?

        use Encode qw(encode); . . . my $decodedContent = encode("ascii", $res->content);

        Where $decodedContent is the text that I am looking for?

        Is there a difference if I use HTTP::Message-> encode($encoding) instead? I'm not entirely sure of the man pages on this.