Replacing special chars with special chars 
Author Message
 Replacing special chars with special chars

I would like to run through a file and replace a set of
special chars (i only have the hex values) with other
special chars..

trying to overcome the windows special char codes and
the unix special char codes difference.

eT



Mon, 03 Apr 2000 03:00:00 GMT  
 Replacing special chars with special chars

Quote:

> I would like to run through a file and replace a set of
> special chars (i only have the hex values) with other
> special chars..

Your code may include something like this.

     tr[\x48\x65\x78\x20]
       [\x63\x6f\x64\x65];

Good luck!

--
Tom Phoenix           http://www.teleport.com/~rootbeer/

Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



Mon, 03 Apr 2000 03:00:00 GMT  
 Replacing special chars with special chars

Quote:

> I would like to run through a file and replace a set of
> special chars (i only have the hex values) with other
> special chars..

> trying to overcome the windows special char codes and
> the unix special char codes difference.

Read the data, and use 'tr' for each chunk of
data (line/record/whatever the chunk you read).

If, say I had such a chunk in the scalar $chunk,
and I wanted to replace each byte with the hex
value of E4 with, say, D0, then I could do it
with

   $chunk =~ tr!\xE4!\xD0!;

See also the Perl Frequently Asked Question (FAQ):

   "How do I change one line in a file/delete a line
   in a file/insert a line in the middle of a file/
   append to the beginning of a file?"

It'll show you the general procedure required for
replacing stuff in a file with other stuff.

You'll find the FAQ in your Perl documentation
directories, or via http://www.perl.com

regards,

    ICL Data Oy
    Finland



Thu, 06 Apr 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Shell special chars in file names?

2. pattern matching with special char

3. escape special chars before loading into MySQL

4. Special chars

5. special chars

6. about special chars when split()

7. Text::CSV with Special Chars?

8. perl/sendmail: encoding special chars

9. is there a way to escape special chars

10. Newbie - Escaping special chars in forms

11. split on special chars (++)

12. Dealing with the special chars in the file name

 

 
Powered by phpBB® Forum Software