I hope this makes sense
Perl version 5.8.4 on Linux
I retrieve the text from a URL by using WWW::Mechanize.
The raw text has
in it. By using
my $result = $mech->content(format => 'text');
it looks like the the
is getting replace with
0xa0 (or octal 240). My goal is just to get plain old
7 bit ASCII, where all 'spaces' should be 0x20.
Now for the fun part, in the script if I uncomment
the lines
use encoding 'latin1';
$result .= "";
I get what I want, but why the need for appending
a empty string to $result ?
Or better asked, what should I be doing in the first
place ?
======================================================
#!/usr/local/bin/perl
use warnings;
use strict; $|++;
use WWW::Mechanize;
#use encoding 'latin1';
#use encoding 'ascii';
#use encoding 'UTF-8';
my $mech = WWW::Mechanize->new();
my $url = "http://www.undeerc.org/wind/winddb/top.asp?TableName=tblDee
+rtrailCO";
$mech->get( $url );
print "1" x 70, "\n";
print "|", $mech->content, "|\n";
my $result = $mech->content(format => 'text');
$result =~ s/[\r\n]//g;
print "2" x 70, "\n";
print "|$result|\n";
#$result .= "";
$result =~ s/\s+/ /g;
print "3" x 70, "\n";
print "|$result|\n";
======================================================
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.