Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Parsing with RegEx into Array

by toolic (Bishop)
on Jun 25, 2010 at 18:16 UTC ( #846578=note: print w/replies, xml ) Need Help??


in reply to Parsing with RegEx into Array

I understand you asked for a regex, but this kinda looks like XML, so here's an XML::Twig parser solution:
use strict; use warnings; use Data::Dumper; use XML::Twig; my $xfile = <<EOF; <foo> <item><i>headline 1</i></item> <item><i>headline2</i></item> </foo> EOF my $t = new XML::Twig(); $t->parse($xfile); my @x; for my $item ($t->root()->children('item')) { push @x, $item->first_child('i')->text(); } print Dumper(\@x); __END__ $VAR1 = [ 'headline 1', 'headline2' ];

Replies are listed 'Best First'.
Re^2: Parsing with RegEx into Array
by mr_p (Scribe) on Jun 25, 2010 at 18:27 UTC
    XML::Twig gave me problems loading it. Here is the error
    Parsing of undecoded UTF-8 will give garbage when decoding entities at + /usr/lib/perl5/vendor_perl/5.8.8/XML/Twig.pm line 731

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://846578]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (10)
As of 2018-07-20 14:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















    Results (435 votes). Check out past polls.

    Notices?