Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Removing Non-Ascii chars from text file

by zentara (Archbishop)
on Jun 07, 2007 at 12:22 UTC ( #619794=note: print w/replies, xml ) Need Help??

in reply to Removing Non-Ascii chars from text file

Look at how this works.
#!/usr/bin/perl $s .= chr for 1..255; print $s,"\n\n"; $s =~ tr/\x20-\x7f//cd; print $s,"\n\n";

I'm not really a human, but I play one on earth. Cogito ergo sum a bum

Replies are listed 'Best First'.
Re^2: Removing Non-Ascii chars from text file
by Anonymous Monk on Nov 19, 2012 at 08:34 UTC
    ^\x20-\x7E This is not ASCII, this is real ascii: ^\x00-\x7F Otherwise it will trim out newlines and other special characters that are part of ascii table!

      Correct. ASCII "includes definitions for 128 characters: 33 are non-printing control characters... and 95 printable characters..."
      See this scanned copy of the original "American Standard Code for Information Interchange (ASCII)" from 1963, the 5th page in particular. This definition is also enshrined in Internet RFC 20.

      <c> ^\x20-\x7E <c> This is not ASCI

      Sure it is, 32 through 126 (precisely all the characters that aren't 32 through 126 )

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://619794]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2019-07-19 16:46 GMT
Find Nodes?
    Voting Booth?

    No recent polls found