Hello again. So here's the deal, I use LWP::Simple to get a web page, then I use HTML::Strip to remove all the markup tags. I am left with a workable text file with maybe a little too much whitespace.
Now the problems start. If I now read this file into an array and then try to grep the array index, it just doesn't work. I'm guessing it is all that whitespace messing things up.
Is there any hope for me?
#! /usr/bin/perl #fetch the webpage my $url = 'http://www.foo'; use LWP::Simple; my $content = get $url; die "Couldn't get $url" unless defined $content; print $content; #strip the tags use HTML::Strip; my $hs = HTML::Strip->new(); my $clean_text = $hs->parse( $content ); $hs->eof; #write to file $append = 0; if ($append) { open(MYOUTFILE, ">clean_text"); #open for write, overwrite } else { open(MYOUTFILE, ">>clean_text"); #open for write, append } #read the file into an array open(MYINPUTFILE, "<clean_text"); # open for input my(@lines) = <MYINPUTFILE>; # read file into list #so far so good, but check below for the troubles. my $search = 'foo'; my @where = grep { $lines[$_] eq $search } 0 .. $#lines; print @where;

will return nothing at all.
The stripped file looks something like below.

    464



      02



  18/03/07
        ST / "Turf" / "B+2"

Edit: g0n - code tags


In reply to html into an array by monkeybus

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.