Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Clarification on greediness

by zejames (Hermit)
on Nov 25, 2004 at 12:41 UTC ( #410380=note: print w/replies, xml ) Need Help??


in reply to Clarification on greediness

Just a little suggestion : why don't you use XML perl modules, like XML::Simple, that will make you code clearer, easier to maintain and to read ?

--
zejames

Replies are listed 'Best First'.
Re^2: Clarification on greediness
by thinker (Parson) on Nov 25, 2004 at 14:03 UTC

    Hi prasadbabu

    I have to agree with zejames that regexes are not the recommended way to parse XML. Especially when XML::Simple is so easy to use (just like it says on the tin). In case you are not familiar with it, here is some sample code, to produce the output you are looking for.

    #!/usr/bin/perl use strict; use warnings FATAL => "all"; use XML::Simple; my $xml = '<pages> <contentmodel> <level>5</level> <first>35</first> <content>some text</content> </contentmodel> <contentmodel> <level>4</level> <first>45</first> <content>some text</content> </contentmodel> <contentmodel> <level>3</level> <first>25</first> <content>maps</content> </contentmodel> <contentmodel> <level>2</level> <first>15</first> <content>some text</content> </contentmodel> </pages> '; my $ref = XMLin($xml); for my $cm(@{$ref->{'contentmodel'}}){ printf "<first>%d</first>\n", $cm->{'first'} if $cm->{'content'} eq 'maps' }; __END__ output <first>25</first>

    cheers

    thinker

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (10)
As of 2020-10-23 11:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (238 votes). Check out past polls.

    Notices?