Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: remove section by section?

by tachyon (Chancellor)
on May 08, 2002 at 05:38 UTC ( [id://164918]=note: print w/replies, xml ) Need Help??


in reply to remove section by section?

Here is some starter code. You essentially have an XML file to parse. You need to know How to RTFM and search the site as this sort of task is very common.

# get your data into a string: my $data = join '', <DATA>; # declare a hash variable my %secs; # use a regex match to get the bits while ($data =~ m|<([^>]+)>([^<]+)</\1>|g ) { $secs{$1} = $2; } print "Regex Method\n"; print "\nSection: '$_'\n", $secs{$_} for keys %secs; # or use XML::Simple to parse it (generally better) ... use XML::Simple; my $hash = XMLin($data); print "\n\nXML Method\n"; print "\nSection: '$_'\n", $secs{$_} for keys %$hash; __DATA__ <xml> <section1> blah1 blah1 </section1> <section2> blah2 blah2 </section2> <section3> blah3 blah3 </section3> </xml>

I would suggest a hash as the data structure because it is easy to index to and delete chunks. XML::Simple will write your hash back to a file for you as well as parse the file directly. Read the docs.

cheers

tachyon

s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://164918]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (None)
    As of 2024-10-15 19:03 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?
      erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.