Wayne Simmons wrote:
> All,
> 
> I didn't see an LWP specific list, so I hope someone here knows about this.
> I'm using LWP agent to submit an HTTP::Request for a url that is returning 
> text/htmlcharset=UTF-8 content type. However it's supposed to be tab
> delimited data but by the time $response->content gets it the tabs are gone
> and it seems to have been space expanded!
> 
> I can see the data from the website through a regular browser and it looks
> like the data is tab delimited in the source view on mozilla (ie the second
> column is all lined up) but when I analyze within perl the data I'm getting
> multiple 0x20 bytes instead of a single 0x09.  
> 
> Is it possible the source is wrong?  Unfortunately I don't have control over
> the source, and I can't post the link to the data (as it requires a
> user/password to access). The code I use is in essence:
> 
> my $browser = LWP::UserAgent->new;
> my $response = $browser->get( $URL );
>       
> my $foo = pack("C",9);
> if ( $response->content =~ /$foo/) 
> {
>       print "found tab!";
> } else
> {
>       print "no tabs!";
> }
> 
> And I get no tabs. Can anyone think of a way to verify the source data is
> correct, and/or know if there is a LWP or HTML header I should be setting to
> prevent tab expansion to spaces (if that's what's happening).

Are you sure there are tabs ?  Have you tried editing the file or
can't you get at the actual file source ?

I would try dumping the content in hex and see what you're getting.

PS:
You can search for a tab a little easier using \t or \x09 instead of
bothering with pack - you could count the tabs like this (assuming tab
is indeed a binary 9 in your source):

my $content = $response->content || '';

if (my $num = $content =~ tr/\t/\t/) {
        print "Found $num tabs\n";
} else {
        print "No tabs\n";
}

# or a bit slower

if (my $num = $content =~ s/\x09/\x09/gs) {
        print "Found $num tabs\n";
} else {
        print "No tabs\n";
}


_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to