in reply to how to retrieve data between <script></script> and save to an array
Output:use Modern::Perl; use Data::Dump qw/dump/; use XML::Twig; my $text; my @results; { local $/ = undef; $text = <DATA>; } my $t = XML::Twig->new( twig_handlers => { script => \&script } ); $t->parse("<wrapper>$text</wrapper>"); say dump(@results); sub script { my ( $t, $script ) = @_; my $text = $script->trimmed_text(); push @results, $text; } __DATA__ <script></script> <script>var onWL=0;</script> <script> var a_fInDelItms = 0; </script>
("", "var onWL=0;", "var a_fInDelItms = 0;")
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: how to retrieve data between <script></script> and save to an array
by curd8341 (Initiate) on Apr 11, 2012 at 00:59 UTC | |
by CountZero (Bishop) on Apr 11, 2012 at 05:59 UTC |