in reply to How to grab a portion of file with regex
It is generally not recommended to use regex matches to parse HTML files.
Instead as swkronenfeld pointed out its better to use the CPAN module HTML::Parser
Below is an example of its usage.-Kiel#!/usr/bin/perl use Modern::Perl; use autodie; use HTML::Parser (); my $p = HTML::Parser->new( start_h => [\&start, 'tagname, attr'], ); open my $fh, '<', shift; $p->parse_file($fh); $fh->close; sub start { my ($tag_name, $attrs) = @_; return unless $tag_name eq 'div'; say 'sample Text' if exists $attrs->{class} and $attrs->{class} and $attrs->{class} =~ /^lastUnit. +*/; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to grab a portion of file with regex
by Anonymous Monk on Mar 15, 2013 at 01:46 UTC | |
by kielstirling (Scribe) on Mar 15, 2013 at 02:46 UTC | |
by Anonymous Monk on Mar 15, 2013 at 04:00 UTC | |
by kielstirling (Scribe) on Mar 15, 2013 at 04:22 UTC | |
by Anonymous Monk on Mar 15, 2013 at 06:39 UTC | |
by 7stud (Deacon) on Mar 15, 2013 at 03:37 UTC | |
by kielstirling (Scribe) on Mar 15, 2013 at 03:53 UTC | |
by Anonymous Monk on Mar 15, 2013 at 03:58 UTC |