Hello Monks,
My script aims to read-in a dummy HTML file from my hard disk (E drive, as the disk is partitioned), call a sub which will run a regex looking for image tags and replacing them with nothing. The interpreter is telling me that I have a global variable which needs an explicit package name, and I've tried to remedy this but still won't work! I'm new the programming, so please bear with me. 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! } return @htmlLines; } for my $i (0..@htmlLines-1) { print $htmlLines[$i]; } print "\n\n"; sleep 2; print "Success?!\n"
Any suggestions/hints as to where I'm going wrong?

Cheers,

Richard

update (broquaint): added formatting


In reply to HTML image tag stripping by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.