Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Removing Control Characters from a File

by jmcnamara (Monsignor)
on Jun 04, 2002 at 22:57 UTC ( [id://171669]=note: print w/replies, xml ) Need Help??


in reply to Re: Removing Control Characters from a File
in thread Removing Control Characters from a File


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://171669]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-04-25 14:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found