Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: find and remove one or more key

by jethro (Monsignor)
on Apr 26, 2013 at 07:41 UTC ( #1030787=note: print w/ replies, xml ) Need Help??


in reply to Remove find tag

The best way to handle xml files is with a module. If you look on CPAN you find some like XML::Simple or XML::Twig

Also you should change your data type to store your keys. Use a hash instead of an array. Why? Because a hash already makes sure that there no key can be repeated. And searching for a key is a lot faster than with an array.

If you don't know how to use a hash, read the docs. It is nearly as simple as an array, but sooo much better for most problems

UPDATE: This is not a code writing service. The script you had was not bad as a first draft. Adapt it a bit, debug it and it should work. Here is a hint:

#Suppose you got a new XML key and value read from the file in $key an +d $value if (not exists $hash{$key}) { $hash{$key}= $value; } else { #drop key }

This is already the meat of your hash handling.


Comment on Re: find and remove one or more key
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (10)
As of 2015-07-02 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (33 votes), past polls