#!/usr/bin/perl # change background color.plx # Program will read in an html file, change background color and print to source file. # 1. No need for file variable yet: open (INFILE, "<".$htmlFile) or die("Can't read source file!\n"); # /background-color:\s*#([0-9a-f]{6});?/ig # /background-color:\s*#([0-9a-f]{6}|[0-9a-f]{3});?/ig use warnings; use diagnostics; use strict; # Declare and initialise variables. my @htmlLines; # Open HTML test file - forward slashes do not need to be escaped. open INFILE, "E:/Documents and Settings/Richard Lamb/My Documents/HTML/dummy1.html" or die "Sod! Can't open this file.\n"; # Assign to an array/list variable. @htmlLines = ; close (INFILE); sub changeBackColour { foreach my $line (@htmlLines) { # case insensitivity and global search for pattern $line =~ s/background-color:\s*\#([0-9a-f]{6}|[0-9a-f]{3});?/background-color:\s*\#FFFFFF;?/ig; } } changeBackColour(); sub printHTML { for my $i (0..@htmlLines-1) { print $htmlLines[$i]; } } printHTML(); # prints the reformatted HTML file in DOS window