in reply to Grabbing part of an HTML page
#!/usr/bin/perl 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" +); for(@files_to_look_in) { local $/; open(HTM_FILE, <$_) || die "Can't open file: $!"; my $file = <HTM_FILE>; if ($file =~ /$start_pattern(.*)$end_pattern/s) { print "$1"; } }
Note: If I hadn't localized $/ (the input record seperator), I would have needed to add a /s modifier to the regular expression to match on the whole file.
cLive ;-)
update: oops, not paying attention "while" is now "for". 2) made a boo-boo - see below...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Grabbing part of an HTML page
by graff (Chancellor) on Mar 29, 2004 at 01:53 UTC | |
by cLive ;-) (Prior) on Mar 29, 2004 at 04:58 UTC | |
by graff (Chancellor) on Mar 29, 2004 at 05:20 UTC | |
by cLive ;-) (Prior) on Mar 29, 2004 at 06:05 UTC | |
|
Re: Re: Grabbing part of an HTML page
by pbeckingham (Parson) on Mar 28, 2004 at 22:30 UTC |