Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Hash Table genaration using perl

by veerubiji (Sexton)
on Sep 30, 2011 at 13:50 UTC ( #928808=perlquestion: print w/ replies, xml ) Need Help??
veerubiji has asked for the wisdom of the Perl Monks concerning the following question:

hi

Comment on Hash Table genaration using perl
Re: Hash Table genaration using perl
by keszler (Priest) on Sep 30, 2011 at 13:54 UTC

    What have you tried? It's great that you posted the test data, but it's hard to help you fix your code without seeing it.

      Hi, thank you very much for reply, i am strugling to store description into a string.
Re: Hash Table genaration using perl
by blue_cowdawg (Monsignor) on Sep 30, 2011 at 14:08 UTC
        Hi, I am trying to create hash table using perl script.

    It is wonderful that you have posted your XML input data as a sample. You haven't posted any Perl code and quite honestly if you are trying to get the monks here to do your work for you I'm not sure that's going to happen.

    If you want broad stroke advice on how to approach the problem, let me take a whack at it for you:

    • First analyze the data you are working with and identify how you want the data organized (data structure) and what data is important and what isn't. Figure out a "key" to identify individual records of data or failing that maybe you want to use an array instead and use numeric indices to select records?
    • Figure out a strategy for parsing the XML to extract the data you want. My personal favorite is to use the CPAN module XML::Simple. OBTW: depending on the arguments it supplies it may organize your data into data structures of its own choosing. So you may want to examine what it has done using Data::Dumper.
    • Probably should have put this as the first bullet item, but make sure your XML is well formed. If it is not, most XML parsers will barf on you which is not pleasant. Getting data chunks in your lap isn't fun.


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      I am trying like this, i am reading xml and i am extracting but i dnt know how to extract each test description and sotre it in a string. Each test description starts with data number like <data> then how to extract each description and store it in a string.I am beginer to perl.

        Take a look at XML::Simple for reading in the XML. It'll work better than greedy regexes.


        Peter L. Berghold -- Unix Professional
        Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Hash Table genaration using perl (XML parse)
by toolic (Chancellor) on Sep 30, 2011 at 14:10 UTC
    You could use one of the XML parsers available on CPAN. I recommend XML::Twig.

    Give one of them a try (read the documentation then write code), and if you still have problems, post specific questions.

      Hi toolic, thanks for your reply,I will try.
Re: Hash Table genaration using perl
by choroba (Abbot) on Sep 30, 2011 at 14:58 UTC
    I usually use XML::XSH2 for XML manipulation. In this case, I would use something like
    $tests := hash Testnumber //DTC ; echo xsh:lookup('tests','0438')/Cause/Formal/Component/BehavioralMode/ +@Probability ;
    To store the "description", you have to define what a description is. An XML chunk?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (11)
As of 2014-12-22 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (127 votes), past polls