#!/usr/bin/perl
# write mods to HTML file.plx
# Program will read in an html file, remove the img tag and rewrite HTML on E-drive.
# 1. No need for file variable yet: open (INFILE, "<".$htmlFile) or die("Can't read source file!\n");
# 2. Alternative: m/]+>(.*?)<\/A>/ - Will not remove closing tag though - why?
# 3. Why is interpreter flipping-out over an 'undefined variable', when
# original regexp, m/]+>(.*?)<\/A>/, is known to work. What am I missing?
use warnings;
use diagnostics;
use strict;
# Declare and initialise variables.
my $pattern1 = '';
my $pattern2 = ']+>';
my $pattern3 = '';
my @htmlLines;
# Open HTML test file and read into array.
open INFILE, "E:/Documents and Settings/Richard Lamb/My Documents/HTML/dummy1.html" or die "Sod! Can't open this file.\n";
@htmlLines = ;
# Call tag-scrapping subs
scrapImageTag();
scrapAnchorTag();
# Removes image tag elements in array
sub scrapImageTag
{ # interates through each element (i.e. HTML line) in array
foreach my $line (@htmlLines)
{
# replace with nothing.
$line =~ s/$pattern1//ig; # case insensitivity and global search for pattern
}
}
# Removes anchor tag elements in array
sub scrapAnchorTag
{ # interates through each element (i.e. HTML line) in array
foreach my $line (@htmlLines)
{
# replace with nothing.
$line =~ s/$pattern2//ig; # case insensitivity and global search for pattern
$line =~ s/$pattern3//ig; # case insensitivity and global search for pattern
}
}
# Replacing original file with reformatted file!
open (OUTFILE, ">E:/Documents and Settings/Richard Lamb/My Documents/HTML/dummy1.html") or die("Can't rewrite the HTML file.\n");
print (OUTFILE @htmlLines);
close (INFILE);
close (OUTFILE);