Perl Scripting to Modify HTML files


Read With Formatting | Free Open Source Tutorials Account

Perl Programming
Thread: Perl Scripting to Modify HTML files


tuckerbai
I am trying to write a script that will search through an html file to a specific anchor and then add html code after the anchor to insert a link onto the webpage.

Does anyone have any code ideas?

md_doc
Is there a specific string you can show us that you are looking for to place something after?


<a href="someurl.html">some text</a>


If that was the url you were looking for and you wanted to place something after it then it would be pretty easy... assuming the text and the url is unique.


$line =~ s/some text</a([^>]*)>/some text</a><a href=\"newlink.html\"</a>/is;


That is what I would do or something similar. I did not get a chance to test the code but it should work for the most part.

You can easily start with the following article though for the code. http://www.opensourcetutorials.com/tutorials/Server-Side-Coding/Perl/perl-scripts-regex/page1.html

Thanks
md