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

Reading in through a port and into a hash?

by basicdez (Pilgrim)
on Oct 16, 2001 at 20:58 UTC ( [id://119187]=perlquestion: print w/replies, xml ) Need Help??

basicdez has asked for the wisdom of the Perl Monks concerning the following question:

Hello wise perl monks... I am asking this question in complete humility. Please help if you can, but do not be to critical on me, as I am trying my best to complete the given task before me. Okay, here is something similar to the data file that will be getting passed into a port for the retrieval of perl...
"DESTINATION" "localhost" "x2pd" "HDR" "HDR-1" "" "HDR-3" "" "" "" "HDR-7" "09/06/2001" 99999 "" "hdr-11" "hd +r-12" "" "" "B" "INI" "INI-1" "" "INI-3" "INI-4" "INI-5" 0 0 "88888888" 9999.99 "PER" "A1" yes "per-3" "" "per-5,per-5,per-5,per-5,per-7,per-5,per-5" "" "77 +7777777" 01/01/71 99 "10101010" 0 0 "13" ""
This is only a small piece of the file, but if you can help me to know how to read this in through a port and then store it somehow (my guess is hash references), then take each field and create an XML tree, that would be awesome. Again, I ask of you not to be overly critical of me as I am only an egg and and am humbly asking for your help with this one. Another side note, notice under the PER packet that there is a comma delimitted field being passed in that would need to be read into one area and then split out for the creation of this tree... Here is how the tree would look...
<?xml version="1.0"?> <application id =”_10”> <account_application> <destination>localhost</destination> <application_type>x2pd</application_type> </account_application> <header> <header-1>HDR-1</header-1> <header-2></header-2> <header-3>HDR-3</header-3> <header-4></header-4> <header-5></header-5> <header-6></header-6> <header-7>HDR-7</header-7> <header-8>09/06/2001</header-8> <header-9>99999</header-9> <header-10></header-10> <header-11>hdr-11</header-11> <header-12>hdr-12</header-12> <header-13>B</header-13> </header> <ini> <ini-1>INI-1</ini-1> <ini-2></ini-2> <ini-3>INI-3</ini-3> <ini-4>INI-4<ini-4> <ini-5>INI-5</ini-5> <ini-6>0</ini-6> <ini-7>0</ini-7> <ini-8>88888888</ini-8> <ini-9>9999.99</ini-9> </ini> <personal> <personal-1>A1</personal-1> <personal-2>yes</personal-2> <personal-3>per-3</personal-3> <personal-4></personal-4> <personal-6></personal-6> <personal-7>777777777</personal-7> <personal-8>01/01/1971</personal-8> <personal-9>99</personal-9> <personal-10>10101010</personal-10> <personal-11>0</personal-11> <personal-12>0</personal-12> <personal-13>13</personal-13> <personal-14></personal-14> </personal> <comment> <personal-5>per-5</personal-5> </comment> <comment> <personal-5>per-5</personal-5> </comment> <comment> <personal-5>per-5</personal-5> </comment> <comment> <personal-5>per-5</personal-5> </comment> <comment> <personal-5>per-7</personal-5> </comment> <comment> <personal-5>per-5</personal-5> </comment> <comment> <personal-5>per-5</personal-5> </comment>
Sincerely and humbly, dez L Please notice that the incoming data stream is seperated by "s in some spots and spaces in others, this is leaving me with great frustration, as you can only imagine.

Replies are listed 'Best First'.
Re: Reading in through a port and into a hash?
by IraTarball (Monk) on Oct 16, 2001 at 22:04 UTC
    I'll admit up front to being a little confused, but I'll take a crack at his any way.

    First, you talk of reading from a port, do you mean a socket? If so, and if you need help here, start with IO::Socket You should be able to read from a socket like a regular file handle.

    Next, parsing your data. You will likely want to read in each line, parse it with split or some regex goop. I'm glazing over this because I want to get to the...

    Next part, writing it to XML. Check out XML::Simple. It's cool. Once you have the data in a hash you can just say XMLout(\%hash, "file.xml"); and you have your xml file. You probably want to set some options so read the docs.

    This is probably not as detailed as you might have hoped, especially the 'goop' part, but read some docs, post some code, and I think you'll find you get usable code posted back.

    Good Luck,
    Ira,

    "rm -rf /"
    ~guest

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-18 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found