Gossamer Forum
Home : General : Perl Programming :

Strange problem under Windows

Quote Reply
Strange problem under Windows
Hi!
I have strange problem. Simple script to getting from URL picture:

#!c:\perl\bin\perl -w

use strict;
use LWP::UserAgent;
use HTTP::Response;
use URI::Heuristic;

my $string_url = 'http://www.google.pl/images/logo_sm.gif';
my $url = URI::Heuristic::uf_urlstr($string_url);
$|=1;
my $ua = LWP::UserAgent->new();
$ua->agent("Hurra proxy script");
my $response = $ua->get($url, Referer=>"http://blabla.com");
if ($response->is_error()) {
die "%s\n", $response->status_line;
}
else {
my $content = $response->content();

#my $bytes = length $content;
#my $count = ($content =~tr/\n/\n/);
#printf "%s (%d lines, %d bytes)\n\n\n\n",
# $response->title()||"(no title)", $count, $bytes;

printf "Content-type: %s\n\n", $response->content_type;
print $content;
}

Under Linux-like systems it is work fine, but under Windows, when i try print $content, i get wrong data... Problem is, what $content has properly size (4707 bytes), but when i print it, and check size of printed data, it is 4376 bytes !!! So Windows prints some extra bytes, and i don't know why ...

Thanks for help,

Filip
Quote Reply
Re: [felippe] Strange problem under Windows In reply to
Ok.. i found it myself :)

It is neccessary to add line:

binmode STDOUT;

just before print $content


Filip