petepdx has asked for the wisdom of the Perl Monks concerning the following question:

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";
======================================================

Replies are listed 'Best First'.
Re: WWW::Mech / Unicode issue ?
by thundergnat (Deacon) on May 10, 2005 at 16:03 UTC

    Odd. Uncommenting those two lines doesn't seem to change anything when I try it.

    For what it is worth, & nbsp; is a non-breaking space which in both Latin-1 and Unicode at ordinal 160 or \xA0. (Space added so entity wouldn't be rendered as the actual character)

    To convert the non-breaking spaces to regular spaces, do a substitution:

    $result =~ s/ / /g;