I'll try to point out a few things that immediately leap out at me...
- You got the right idea by using -w. I recommend using strict as well to prevent typos, etc. There's plenty of stuff around PerlMonks extolling the virtues of it, so I won't go over it here.
- You're not checking the status of opening your file for reading. Try something like this instead: open( F, '<', 'pageinfo.htm' ) or die "Can't open pageinfo.htm: $!";
- Your first while loop to print the contents of the file can be shortened to print while <F>;
- You're not closing the file after you're done with it.
- You should check the result of your LWP request using $request->is_success and show appropriate error messages, etc.
- I'm not even sure what you're trying to do with those last two while loops. The $result->content is one big scalar, so one greedy substitution on it will take care of each of these. I.E.: s/</</g; s/\n/<BR>/g;
And finally, here's a quick example of using HTML::TokeParser to get the meta tags out of an HTML document:
#!/usr/bin/perl -w
use strict;
use HTML::TokeParser;
use LWP::Simple;
my $source = get( shift || 'http://www.perlmonks.org' );
my $parser = HTML::TokeParser->new( \$source );
while ( my $tag = $parser->get_tag( 'meta' ) ) {
print $tag->[3], "\n";
}
print "Done.\n";
I'll leave it as an excercise to use this in a CGI document and format your output accordingly. I hope all this helps... good luck!
"As information travels faster in the modern age, as our days are crawling by so slowly." -- DCFC
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.