CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Program that adds a phrase in footer of every page.

 



arjunetal
New User

Apr 2, 2009, 3:34 AM

Post #1 of 5 (3030 views)
Program that adds a phrase in footer of every page. Can't Post

Hello,

Well I want a program that can add a phrase on footer of every page.

Actually I don't want to manually edit every page as they are a lot in number. Moreover I will need to add that phrase on every new page.
This is a very tuff job, and I want a alternative for this.

I want my server to do so, before the file goes to user level.

Example:

Suppose the html file is:

<html>
<head>
<tiltle></title>
</head>
<body>
<p>Hello World!</p>
</body>
</html>

Now what I want is that output should be:

<html>
<head>
<tiltle></title>
</head>
<body>
<p>Hello World!</p>
<p>How are you</p>
</body>
</html>

So exactly what I want is to add <p>How are you</p> before </body> tag.

I came up to know that it is possible via Perl script.
I know that I have to edit .htaccess file on my server, but I exactly don't know what to do aas I am a newbie in perl script.

Can you suggest me any method to do so.
Arjun Gupta
Team MUUNS.com
<a href="http://www.muuns.com">http://www.muuns.com</a>


PGScooter
stranger

Apr 5, 2009, 5:41 PM

Post #2 of 5 (2983 views)
Re: [arjunetal] Program that adds a phrase in footer of every page. [In reply to] Can't Post

Hi Arjun,

You are correct- you can easily do this in Perl!

There are a couple of ways you can do this:

1. process the file line by line (it's very easy, just use "open" and while (<FILEHANDLE>). Then check to see if the current line is equal to </body> (the code for this is "if ($line eq '</body>')..."). If it is, then print your header to the new file followed by the current input line; if it is not (ie, the if is false), then just print the current line to the input file.

2. you can use a "regular expression". If you do this, be sure to have the regex span over lines (there is some modifier).

I apologize for not writing the script for you, but this is really an excellent opportunity for you to start learning perl!!! I would suggest option 1 because that will teach you some good techniques. You should be able to get started just by doing some googling (ie. "perl read file"). And whenever you get stuck along the way, post on this forum what you have done and where you are stuck.


good luck!
The more you teach me, the more I learn. The more I learn, the more I teach.


JenniC
Novice

Apr 7, 2009, 9:53 AM

Post #3 of 5 (2924 views)
Biterscripting script that adds a copyright notice in every .html page. [In reply to] Can't Post

Hi arjunetal:

You said:


In Reply To


So exactly what I want is to add <p>How are you</p> before </body> tag.



This can be done very simply with biterscripting. (I had the same problem - wanted to insert copyright notices at the end of each page in tons of pages. Someone pointed me to biterscripting. It works great !) Here is a script. I will assume your html page is at C:/mysite/page.html.


Code
   


# Read in the page into a variable.

var str page ; cat "C:/mysite/page.html" > $page

# Insert "<p>How are you</p>\n" before "</body>".

sin -c "^</body>^l" "<p>How are you</p>\n" $page > $page

# Write page back.

echo $page > "C:/mysite/page.html"



You can also do this for all .html files in a folder (and subfolders). Use the following script.


Code
   

# Collect a list of .html files

var str list ; find -n "*" "C:/mysite" > $list

# Process one file at a time.

while ($list <> "")

do

# Get the next file.

var str file ; lex "1" $list > $file

# Call the above code

# Change cat "C:/mysite/page.html" > $page to cat $file > $page

# Also, change echo $page > "C:/mysite/page.html" to echo $page > { echo $file }

done



If you don't have biterscripting yet, download it free from http://www.biterscripting.com. Download and install all their sample scripts using the following command.


Code





Jenni

(This post was edited by JenniC on Apr 7, 2009, 9:54 AM)


KevinR
Veteran


Apr 7, 2009, 10:04 AM

Post #4 of 5 (2921 views)
Re: [JenniC] Biterscripting script that adds a copyright notice in every .html page. [In reply to] Can't Post

hehehe.... so you finally managed to find this forum to post your BS spam.
-------------------------------------------------


arjunetal
New User

Apr 8, 2009, 7:35 AM

Post #5 of 5 (2897 views)
Re: [JenniC] Biterscripting script that adds a copyright notice in every .html page. [In reply to] Can't Post

thanks.......but i want a perl script to do so not BS.
Arjun Gupta
Team MUUNS.com
<a href="http://www.muuns.com">http://www.muuns.com</a>

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives