Hello holy ones,
I am working on a piece of code which will extract an image tag from an HTML doc I've read-in from my hard-drive. The '$i' index in the array is throwing a 'global symbol "$i" requires explicit package name..'. Here's the 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, "E:\\Documents and Settings\\Richard Lamb\\My Documents\\
+HTMLworkspace\\HTML practice\\My First Page!\\firsttest\.html" or die
+ ("Sod! Can't open this file.\n");
@htmlLines = <INFILE>;
scrapTag(); # calls method to remove image tags
sub scrapTag # removes image tags from HTML document
{
while($htmlLines[$i] =~ m/<IMG\s+([^>]+)>/ig) # finds each instance
+of image tag in the input file
{
s/<IMG\s+([^>]+)>/ig//ig # replaces each instance of image tag wit
+h nothing!
}
}
for my $i (0..@htmlLines-1)
{
print $htmlLines[$i];
}
print "\n\n";
sleep 2;
print "Success?!\n";
Where am I going wrong, folks?
Cheers,
Richard
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.