#!/usr/bin/perl ################################################################################ ### insert.pl ### inserts new lines in html files on www.psyke.org ### ### Copyright (C) 2002 Ratatosk / Morten Wulff ### ### This program is free software; you can redistribute it and/or ### modify it under the terms of the GNU General Public License ### as published by the Free Software Foundation; either version 2 ### of the License, or (at your option) any later version. ### ### This program is distributed in the hope that it will be useful, ### but WITHOUT ANY WARRANTY; without even the implied warranty of ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ### GNU General Public License for more details. ### ### You should have received a copy of the GNU General Public License ### along with this program; if not, write to the Free Software ### Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ################################################################################ ### REVISIONS ### Begun : 03/07/2002 : Morten Wulff ### 1.0.0 : 04/07/2002 : Morten Wulff use strict; ################################################################################ ### INIT ################################################################################ my $sitepath = '/path/to/site'; ### list of directories to process my @dirs = qw(dir1 dir2); ### glob pattern my $pattern = '*.html'; ### list of files to exclude from processing my @exclude = qw(index.html); ### what to insert at which linenumber my %insert = ( 12 => "insert this at line 12\n", 34 => "insert this at line 34\n" ); ################################################################################ ### MAIN ################################################################################ my %exclude; @exclude{@exclude} = ('1') x @exclude; foreach my $dir ( @dirs ) { ### change dir my $currentdir = join '/', $sitepath, $dir; chdir( $currentdir ) or die "Could not change into $currentdir\n$!\n"; print "\nchanged into : $currentdir\n"; foreach my $file ( glob($pattern) ) { next if $exclude{$file}; open (IN, $file) or die "Could not open $file\n$!\n"; my @lines = ; close IN; print "processing : $file\n"; my $offset = -1; foreach my $line ( sort keys %insert ) { my $position = $line + $offset; splice @lines, $position, 0, $insert{$line}; $offset++; } open (OUT, ">$file") or die "Could not open $file\n$!\n"; print OUT @lines; close OUT; } } ################################################################################ ### SUBS ################################################################################