[Canberra-pm] SEC: UNCLASSIFIED:-A LITTLE HELP...

caroline.scerri at defence.gov.au caroline.scerri at defence.gov.au
Wed Oct 2 01:04:56 CDT 2002


Hello,

the following is a script which goes through two directory levels of the current working directory, upon finding a htm or
html extension on a file alters the line which calls
for the cascading style sheet specified at the command line and create a new file which has the new
cascading style sheet reference, also specified at the command line.
The result (was hoping) should be an exact copy of the htm or html file with the altered <LINK> reference, instead i am getting a mirror image
directory
and file structure in the temporary directory, all files are of zero length.
Can someone please shed some light, the way i am attempting to redirect STDOUT ie `open (OUT_FILE, ">>$tmp_html_file")` ,
does not seem to be working.
Thanks

Caroline

#!/usr/local/bin/perl
#
# Script to quickly change the cascading style sheet being used by pages under
# the directory it is executed from. Only executes on current directory and any
# first level nested directory.
#
use strict;
use Shell qw(mv);

my $usage = "usage: $0 old_filename new_filename\n";
my $old_css = shift;
my $new_css = shift;
my @html_files = <*.html */*.html *.htm */*.htm>;
my $TMP = "./TMP";
my $CSS = "./NOC/css";
my @tmp_html_files = <$TMP/*.html $TMP/*/*.html $TMP/*.htm $TMP/*/*.htm>;

if ( ! -e "$CSS/$new_css" ) { print "$CSS/$new_css Does not exist, dying\n"; exi
t 1; }

foreach my $html_file ( @html_files )
{
   if ( -f $html_file )
   {
     my $tmp_html_file = "$TMP/$html_file" ;

     open (FILE, "$html_file") or print "Couldn't open $html_file, Skipping: $!\
n";
     open (OUT_FILE, ">>$tmp_html_file") or print "Couldn't create $tmp_html_fil
e, Skipping: $!\n";
     while (<FILE>)
     {
        if ( /(^\<LINK .*=\".*css\/)($old_css)(\".*\>)/ )
        {
          print "${1}${new_css}${3}";
        }
        else
        {
          print "$_";
        }
     }
     close OUT_FILE;
     close FILE;
##These lines will copy the altered files from there temporary location a mirrored directory structure of the files
## it just went through and copy them back to their appropriate production environment. However all they do now is clobber
## my good files with files of the same name but zero length.
     ##mv("$tmp_html_file", "$html_file");
     ##cp("${tmp_html_file}", "$WEB\/$html_file");
   }
}





More information about the Canberra-pm mailing list