in reply to Unexpected output from my PERL program. WHAT is my problem???

my C program prints out "HELLO--HELLO" with nothing in between

You seem to be implying that print extracted the first 6 characters and the last 6 characters of the string it was given. That's nonsense.

If the string passed to the parent process and therefore print contains nothing between the dashes, it's because $decoded_content is empty, which means the response's body was empty for that request.

You're going to insist the response wasn't empty, that it contained the UTF-16be document discussed elsewhere. And I agree. That means the test you said you ran is different than the one you said you ran. The problem is that you are treating the downloaded file as a NUL terminated string. That's a bug in your C program.

I don't get this if I print a regular string variable that I created, to file.

Good, that means there's nothing messing with your file handles. You are saving what you get.

With that I see it, except it obviously is encoded UTF16BE because of the "@^H@^e@^l@^l@^l@^o" characters I see.

I believe you mean UTF-16be. The case doesn't matter, but you missed the dash.

So the only problem is that you want to extract some data from the file you are downloading. For starters, we need to know in what format is the file you are downloading, and in what encoding do you want the extracted data to be.

Update: Updated response to first quote.

Replies are listed 'Best First'.
Re^2: Unexpected output from my PERL program. WHAT is my problem???
by URAvgDeveloper101 (Novice) on Nov 04, 2009 at 16:21 UTC
    Then the server returned no content in its response.

    Then how come if I call the Perl script by itself (on the command line and NOT from my C program), it prints "HELLO-Hello-HELLO" with no blank to stdout?

    So the only problem is that you want to extract some data from the file you are downloading. For starters, we need to know in what format is the file you are downloading, and in what encoding do you want the extracted data to be.

    I set the content-type explicitly in the webserver to return content as "text/plain". I am just trying to print out simple text and nothing else. I want the format to be latin1/iso-8859-1. I want to get the same behavior as if I simply issued a "print $var" command as in the original posting example. I'm getting two different behaviors that I don't think i should expect to get.

      Then how come if I call the Perl script by itself, it prints "HELLO-Hello-HELLO" with no blank to stdout?

      I've already updated my earlier post with an answer to that. ("You're going to insist ...")

      I am just trying to print out simple text and nothing else. I want the format to be latin1/iso-8859-1

      binmode(STDOUT, ':encoding(iso-8859-1)'); print $response->decode_content(default_charset => 'UTF-16be');
        ikegami: Thanks for all your help. That was all that I needed....those TWO LINES:

        binmode(STDOUT, ':encoding(iso-8859-1)'); print $response->decode_content(default_charset => 'UTF-16be');


        I don't know how I missed that the first time you posted it.