> Dan Muey wrote: > >>I have ~97 HTML documents that I need to strip the footer > >>(about 15 lines) from and > >>replace with a different block of text. The footer is > >>formatted differently in some of the > >>HTML files, but they all start with the line: > >> > >><table border="0" width="100%" height="5%"> > >> > >>How can I replace everything after that particular line with > >>a custom block of text? Thanks. > > > > > > Here's one way, you say the files are html so slurping > shouldn't hurt: > > > > [untested - for principle demo only] > > #!/usr/bin/perl -w > > use strict; > > use File::Slurp; > > > > my $newhtml = '</table></body></html>'; > > my $split = '<table border="0" width="100%" height="5%">'; > > my @files = qw(index.html contact.html); # populate this by hand or > > automatially if you want > > > > my $count = 0; > > for(@files) { > > print "Starting $_ ..."; > > my $html = read_file($_); > > > > my ($firstpart) = split $split, $html; # may need to > tweak around > > with this > > > > write_file($_, "$firstpart$split$newhtml"); > > print "Done!\n"; > > $count++; > > } > > > > print "\nFinished : $count files processed.\n"; > > This slightly modified version of your script seems to work just fine: >
Cool. > #!/usr/bin/perl -w > use strict; > use File::Slurp; > > my $newhtml = '<! Old footer snipped here>\n</body></html>'; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ The only problem I see here you have enter the same data twice leaving room for mistakes you have to fix. So by leaving it out of $newhtml and using print "$firstpart$split$newhtml\n"; # or add some newlines for readability You gaurantee the same data with no mistakes. DMuey > my $split = '<table border="0" width="100%" height="5%">'; > my @files = qw(uc.html); # populate this by hand or > automatially if you want > > for(@files) { > print "Starting $_ ..."; > my $html = read_file($_); > > my ($firstpart) = split $split, $html; # may need to > tweak around with this > > # write_file($_, "$firstpart$split$newhtml"); > print "$firstpart$newhtml\n"; > print "Done!\n"; > } > > -- > Andrew Gaffney -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>