I have been having an extremely trying 30 minutes or so, trying to regex out no-break space unicode entities, represented in my very large raw text file as \302\240. I was just about to post a request for some help, but figured out a solution to my problem. Perhaps it isn't the best solution, but I was unable to find anything concise which solved my problem, on the web, but I suppose there are others out there who have, or will have the same problem - so here's a very short, very simple solution:
#!/usr/bin/perl -w
use warnings;
use strict;
binmode(STDIN,":bytes");
binmode(STDOUT,":bytes");
while(<>){
chomp;
s/\302\240//g;
s/\s+/ /g;
print $_."\n";
}
This completely solved my problem. If it is incomplete, or not a very clever thing to do, please improve it. If it solves somebody elses problem as well - GREAT!
joe 2006-09-14 Retitled by planetscape, as per Monastery guidelines ( keep:0 edit:12 reap:0 )
Original title: 'Annoying Problem: solved'
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|