You have a problem with the undeclared
$i in the
while($htmlLines[$i] line. Also, you do not use the index of the array in the loop, so consider using a
for(each) loop.
Then, your substitution is wrong, it should be
...//ig instead of
/ig//ig. And you don't have to look for a match, just do a global replace; that is going to save you a little time on large files.
And one more thing: You seem to be using a Windows environment (the "Documents and Settings" line). In this case you can make the first line just
#!perl, because
/usr/bin won't exist anyways.
Hope I helped.
P.S.: Here is your (hopefully) fixed code:
#!/usr/bin/perl
#htmltest2.plx
# Program will read in an html file, remove the img tag and print out
# no need for file variable yet: open (INFILE, "<".$htmlFile) or die("
+Can't read source file!\n");
use warnings;
use diagnostics;
use strict;
my @htmlLines;
open INFILE, "t.htm" or die ("Sod! Can't open this file.\n");
@htmlLines = <INFILE>;
@htmlLines = scrapTag(@htmlLines); # calls method to remove image tags
sub scrapTag # removes image tags from HTML document
{
my @htmlLines = @_;
for (@htmlLines) {
$_ =~ s/<IMG\s+([^>]+)>//ig # replaces each instance of image tag
+ with nothing!
}
return @htmlLines;
}
for (@htmlLines)
{
print;
}
print "\n\n";
sleep 2;
print "Success?!\n"
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.