[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Re-write closing tags

Posted on 2009-02-16
8
Medium Priority
?
212 Views
Last Modified: 2012-05-06
I have a perl script take collects info from a form and saves it as an append html file, my problem is at the moment my code

Opens the html file and plonks the form data at the end of the html file, below the closing tags as you would expect being appended :-)

I would like some help with somehow removing the </body></html> tags, so I can write my form data the reprint the closing tags each time a new form is submitted.

Sounds easy but I can't find any help on this, maybe my search description is a little shady, shame substring for a whole file is not method...
0
Comment
Question by:Dan-LL
  • 5
  • 2
8 Comments
 
LVL 85

Assisted Solution

by:ozo
ozo earned 180 total points
ID: 23654532
s#</body></html>#the form data at the end of the html file</body></html>#;
0
 
LVL 1

Author Comment

by:Dan-LL
ID: 23654901
not got clue what to do with this, ;-)

this is what I have the $insertscroll is my data in a pretty format.

open (INFO,">>$scrpath$scr1");
print INFO "$insertscroll";
close (INFO);

what should I do, somthing like (cos it don't work) like this.

open (INFO,">>$scrpath$scr1");
print INFO s#</body></html>#$insertscroll</body></html>#;
close (INFO);


sorry ozo, I normally can get it from your answers but I am struggling tonight, must be the cold UK weather...
0
 
LVL 1

Author Comment

by:Dan-LL
ID: 23655259
a little help, please....

tried this

my $orgtext="</body></html>";
my $newtext="dan</body></html>";

open (INFO,">>$scrpath$scr2");

my $intext=~s/$orgtext/newtext/gms;
print INFO "$intext";
close (INFO);

don't work, I will drowned in my own tears very soon...
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:Dan-LL
ID: 23655455
this works but is a little messy

my $tags="</body></html>";
my $datatags="$insertscroll</body></html>";

undef $/; #slurp mode, read files in a whole


open INFO, "$scrpath$scr2";
my $intext=<INFO>;
close INFO;


open OUT, ">$scrpath$scr2";
$intext=~s/$tags/$datatags/g;
print OUT $intext;
close OUT;
0
 
LVL 85

Expert Comment

by:ozo
ID: 23656602
what do you consider messy?
that there is no error checking on the opens?
that it  reads the entire fine into memory instead of processing a line at a time?
that it doesn't allow any space between </body> and </html>?
0
 
LVL 39

Accepted Solution

by:
Adam314 earned 320 total points
ID: 23660643
Instead of opening the file for read access, closing, then opening for write access, then closing - you could open for read/write:

my $tags="</body></html>";
my $datatags="$insertscroll</body></html>";
 
undef $/; #slurp mode, read files in a whole
 
 
open(INFO, "+<$scrpath$scr2") or die "Could not open: $!\n";
my $intext=<INFO>;
$intext=~s/$tags/$datatags/g;
seek(INFO, 0, 0);  #Go back to beginning of file
print INFO $intext;
close INFO;

Open in new window

0
 
LVL 1

Author Comment

by:Dan-LL
ID: 23662028
are now, that is a nice way of doing it, saves opening and closing the file twice, like that and will accept that adam314.

as ozo got me on the right track and adam has pretty'ed up the code I will share the points around, afterall I think you 2 have writen more of my website that I have over the past few months.
0
 
LVL 1

Author Closing Comment

by:Dan-LL
ID: 31547548
thanks once again, glad your around when I need you... ;-)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question