Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Removing Control Characters from a File

by Abigail-II (Bishop)
on Jun 04, 2002 at 15:35 UTC ( [id://171515]=note: print w/replies, xml ) Need Help??


in reply to Removing Control Characters from a File

This will remove ^X's from your file
perl -0777lpwi -030e0 your_file

Study of man perlrun will explain why this works.

Abigail

Replies are listed 'Best First'.
Re: Re: Removing Control Characters from a File
by jmcnamara (Monsignor) on Jun 04, 2002 at 22:57 UTC

    Very nice. This merits a closer look:
    perl -0777lpwi -030e0 file 0777 Set $/ to 0777. l Chomp $\ and set $\ = $/. Thus $\ = 0777. p Loop over file and print. w Turn warnings on. i Make the changes in-place. 030 Set $/ to 030 (^X). $\ is still 0777. e0 Empty program.

    So in effect this splits the file into records divided by ^X, chomps ^X from the end of each record and prints out the records with 0777 appended at the end. However, (and I'm not certain about this) since there is no character with that value it actually appends ''. Thus, the ^X's are removed from the file.

    So in a way the program is functionally equivalent to:     perl -i -pe 's/\30//g' file

    I say functionally equivalent since there is no aesthetic equivalence. :-)

    --
    John.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2024-04-25 05:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found