in reply to Grabbing part of an HTML page

Try this, but beware of:

#! /usr/bin/perl -w use strict; my $start_pattern = '<!-- start section-->'; my $end_pattern = '<!-- end section -->'; my @files_to_look_in = ('/path/to/files1.html', '/path/to/files2.html' +); my $write_line = 0; foreach (@files_to_look_in) { open HTM_FILE, "<$_"; while (<HTM_FILE>) { $write_line = 1 if /$start_pattern/i; $write_line = 0 if /$end_pattern/i; print $_, "\n" if $write_line; } close HTM_FILE; }

Replies are listed 'Best First'.
Re: Re: Grabbing part of an HTML page
by kingdean (Novice) on Mar 28, 2004 at 22:45 UTC
    pbeckingham, Thanks for your reply. I tried this and it still doesn't work. I do not get an error, but just nothing gets printed. One question, if I wanted to use a URL path such as "http://www.mysite.com/" instead of the local path /usr/etc could I do this? Thanks Dean

      kingdean, I updated my code to include my @files..., and it works on my test files. That's what I get for adding in use strict at the last moment, and not using it from the start, as we all should!

      Perhaps you could show us your test files?

      If you use a URL instead of a local path, it will not work - the open function does not get web pages. You would use LWP::Simple or similar to read the page for you, but that is something you can easily find elsewhere on this site.