Click here to get back home

text substitution question

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
text substitution question pauls 03-10-2008
Posted by pauls on March 10, 2008, 8:14 pm
Please log in for more thread options
I am trying to figure-out how to eliminate any occurrences of the
following text:

</font>

in a text file.

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

s/</font>//g;

But, this does not eliminate the text.


Any help appreciated!

Thanks!

P.

Posted by Riad KACED on March 10, 2008, 8:54 pm
Please log in for more thread options
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 :

m/http:\/\/\w+/(\w+\/)*\w\.html/

But I prefer :

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

Hope it helps !

Riad.

Posted by Dr.Ruud on March 10, 2008, 8:57 pm
Please log in for more thread options
pauls schreef:

> I am trying to figure-out how to eliminate any occurrences of the
> following text: </font> in a text file.
> Usually I try to do some operation on the input file $_ like this:
> s/</font>//g;
> But, this does not eliminate the text.

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."

Posted by John Bokma on March 10, 2008, 10:02 pm
Please log in for more thread options

> Usually I try to do some operation on the input file $_ like this:
>
> s/</font>//g;
>
> But, this does not eliminate the text.

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

One solution:

        s{}g;
        

--
John

http://johnbokma.com/

Posted by Jürgen Exner on March 10, 2008, 11:31 pm
Please log in for more thread options
>s/</font>//g;
>But, this does not eliminate the text.
>Any help appreciated!

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.
        s+</font>++g;

And PLEASE enable strictures and warnings.

jue

Similar ThreadsPosted
text substitution May 23, 2007, 8:42 pm
Text parsing and substitution May 19, 2006, 6:17 am
need help for text substitution using Perl October 20, 2006, 4:51 pm
havoing trouble with text substitution August 15, 2007, 5:06 pm
substitution question October 4, 2006, 8:56 am
pattern substitution question April 21, 2006, 1:10 pm
String Substitution question January 25, 2007, 6:51 pm
another character substitution question August 21, 2007, 4:07 pm
Text::Template Question March 8, 2005, 7:42 am
Text::Template question May 25, 2007, 11:42 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap