Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

replace string

by sandy1028 (Sexton)
on May 18, 2009 at 08:18 UTC ( [id://764597]=perlquestion: print w/replies, xml ) Need Help??

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

Hi, I have to read the file and if I find the characters like &ldquo,&rdquo,&rsquo I have to replace it with some characters.
$data =~ s/“/“/g; # change the lines $data =~ s/”/”/gi; $data =~ s/’/’/gi;
But this is not replaced in the file when it occurs. How to do this

Replies are listed 'Best First'.
Re: replace string
by CountZero (Bishop) on May 18, 2009 at 08:26 UTC
    Do you want to replace the actual “”’characters or their HTML-entities?

    One possible reason for the failure could be that you are trying to replace the actual characters but your are looking for them by using their HTML-entities names; or the character codes you are checking for are not the same as those used in your file (different codepage).

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: replace string
by moritz (Cardinal) on May 18, 2009 at 08:27 UTC

    Please take a look at HTML::Entities, it might help you doing what you want in a more general way.

Re: replace string
by Utilitarian (Vicar) on May 18, 2009 at 08:30 UTC
    Could you attach a sample of your source file, the regexes you have in place should work as expected, provided the characters in the file are as you expect.
      How to convert XHTML entity characters to XML form
        No need, XHTML is XML
Re: replace string
by Anonymous Monk on May 18, 2009 at 08:21 UTC
    “ is made of 7 characters, you probably only have one

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-19 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found