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

Re: Removing duplicate subtrees from XML

by elusion (Curate)
on Dec 03, 2002 at 01:55 UTC ( #217105=note: print w/replies, xml ) Need Help??

in reply to Removing duplicate subtrees from XML

I can see right now a BIG problem with this line:

if ($XML_process_line =~ /^(\d{1,10})([\%|\<].{1,1000}\>)/){

I don't think it does what you want. First of all, this: [\%|\<]. You use [] and |, I think you want one or the other. If you want to alternate between % and <, use [\%<].

Second, and more important, this: .{1,1000}>. Perl's regexes are greedy, that means that if you do this: "<one></one>" =~ /<(.{1,1000})>/;print $1;, you're going to get one></one printed, because it matches as many characters as possible before stopping.

Instead, you'd want to use [\%|\<][^>]{1,1000}>, which uses a negative character class.

That being said, this is hard to do and even harder to do right, so you should use a module. I would suggest XML::Twig, but there plenty of others as well.

elusion :

Update: I also noticed that you use two variables for your line. You assign to $XML_line, but use your regex on $XML_process_line. Remember to use -w and strict.

Replies are listed 'Best First'.
Re: Re: Removing duplicate subtrees from XML
by matth (Monk) on Dec 03, 2002 at 11:27 UTC
    reply to Update. Well spotted. I hand edited that variable in an attempt make the variable names more meaningfull, prior to pasting. Thanks for all the advice.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2020-08-07 10:05 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (44 votes). Check out past polls.