text substitution question

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I am trying to figure-out how to eliminate any occurrences of the
following text:


in a text file.

Usually I try to do some operation on the input file $_ like this:


But, this does not eliminate the text.

Any help appreciated!



Re: text substitution question

Hi Paul,

You need to protect the / in /font.

Try something like : s/<\/font>//g;

That's the simple way I see in your case. If you have patterns with a
lot of slashes, It is worth to change the separator.
If for example you want to match a web address, you could write :


But I prefer :

m=http://\w+/(\w+/)*\w\.html= # = as a separator, this is an example !

Hope it helps !


Re: text substitution question

pauls schreef:

Quoted text here. Click to load it

When a string contains a slash, you need to either
choose a different separator in the substitute
command, like s#</font>##g, or escape the slash,
like s/<\/font>//g. I prefer the first.

Affijn, Ruud

"Gewoon is een tijger."

Re: text substitution question

Quoted text here. Click to load it

You probably got an error, next time *always* include the exact error.

One solution:




Re: text substitution question

Quoted text here. Click to load it

If you had used strict and warnings then perl would have helped you already:

    Useless use of division (/) in void context at t.pl line 2.
    Bareword "g" not allowed while "strict subs" in use at t.pl line 2.
    t.pl had compilation errors.

Now, why would perl believe there is a division in that line? Maybe because
there is a surplus slash aka division sign? I am counting 4 where there
should be only three.

Simple solution: use a different seperator for the s command, e.g.

And PLEASE enable strictures and warnings.


Re: text substitution question

pauls wrote:
Quoted text here. Click to load it
Thanks folks, much apprecaited!

Site Timeline