http://www.perlmonks.org?node_id=188907

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

I've been regretably away from my mistress, Perl, for a while, and now I thougt I would whip out a short script to do some global text edits on a bunch of html files.

I was able to come up with something but it raised a question. Can you write a regex that matches all strings not containing the substring string 'foo'?

Here are my particular details...

I have a bunch of html files with blank images as spacers, but these don't always render right in mozilla unless they have a 'style="display:block"' attribute. Some designers were good about adding these and some were not, leading to fles whith a mix of haves and have not image tags. So what I thought was, "Find all the image tags that don't have a 'style="display:block"' attribute and add it. But how would you right that? I came up with:
#!/usr/bin/perl while(<DATA>) { if(m/<img\s+src="\/images\/blank.gif"/ && !m/display:block/) { print; s|(<img\s+src="/images/blank.gif".*?)>|$1 style="display:block +">|; print; } } __DATA__ <img src="/images/blank.gif" border="0"> <img src="/images/blank.gif" border="0" style="display:block" > <img src="/images/blank.gif" border="0">
this works, but it seems that I should be able to do this in a single s/// instead 2 matches and a swap. Thanks for taking the time to look at my post. I did a search for docs before posting but I could certainly have missed something. Pointers to pertinent nodes are appreciated.

Ira,