Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

finding and deleting the value of special characters

by blacksmith (Hermit)
on Jun 20, 2001 at 22:59 UTC ( [id://90141]=perlquestion: print w/replies, xml ) Need Help??

blacksmith has asked for the wisdom of the Perl Monks concerning the following question:

I have a series of files with a number of characters such as &k2S and &l3A and countless others located with the text. All of these annoyances have the first two characters in common then 3 varying characters following. How do I find out what the value of these characters are and then delete them from my file. I have looked at the tr/// operator, but I am having trouble getting a grasp of its full potential. Any advice would be greatly appreciated. Blacksmith.
  • Comment on finding and deleting the value of special characters

Replies are listed 'Best First'.
Re: finding and deleting the value of special characters
by Masem (Monsignor) on Jun 20, 2001 at 23:04 UTC
    You probably want to use s/// instead of tr, as your annoyances have multiple characters. You can easily use something like s/\\&.{3}//g to remove all instances of your blurb, with the only stipulation that you mind need to enter the numeric code for that first character instead of the character itself to have the perl engine deal with it right.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
      Thanks for the suggestion. I just finished reading a thread discussing the difference between tr/// and s///. I plan to give it a try. Now I am wondering how to find the numeric code of the first character. Blacksmith.
        I believe that ord() might be what you're looking for.

        stephen

Re: finding and deleting the value of special characters
by rrwo (Friar) on Jun 20, 2001 at 23:43 UTC

    Another idea might be to use a hash to translate these. Something like this:

    $line = 'foo ?&k2S bar ?&13A baz'; %cvt = ( 'k2S' => 'AAA', '13A' => 'BBB', ); $line =~ s/\?\&(...)/$cvt{$1}/g; # prints "foo AAA bar BBB baz" print $line, "\n";

    If there's a way of decoding these symbols, you could write a separate routine to create the hash first.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2024-04-23 22:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found