Help to parse text file

K

kitty

Hi,
Iam new to perl and iam still reading up on regular exp and modules
(its something that can be extended for a long time ) !!
I want to build a parser/lexer (which is more appropriate ?) for a text
file which has a format similar to an xml file.

<GRAPH NAME="471138343152490055" VERSION="V3.0" APP_VERSION="2.7.2.8">
<NODE GUID="471138342839500090" TYPE="######"/>
<PROP GUID="471138342839500090" NAME="Unit" TYPE="Unit Conversion"
ATTRIBUTES="propagates editable !graphical visible !members !required "
SETON="1138343152541" SETBY="kitty" EXPR="On" />
<PROP GUID="471138342839500090" NAME="ODE Solver Settings" TYPE="ODE
Solver Settings" ATTRIBUTES="propagates editable !graphical visible
!members !required " SETON="1138343152549" SETBY="kitty" EXPR="&lt;E
Parameter_for_how_often_Jacobian_should_be_calculated=&quot;0.001&quot;
The_Rounding_Unit=&quot;1e-16&quot;
Absolute_Error_Tolerance=&quot;1e-15&quot;
Relative_Error_Tolerance=&quot;1e-7&quot; /&gt;" />
....
</GRAPH>

The output should list certain properties of a node..
NODE TYPE = "#######"
PROPERTIES :
NAME="Unit"
Value (EXPR) = "On"
NAME="ODE Solver Settings"
Value =
"Parameter_for_how_often_Jacobian_should_be_calculated=&quot;0.001&quot;
The_Rounding_Unit=&quot;1e-16&quot;
Absolute_Error_Tolerance=&quot;1e-15&quot;
Relative_Error_Tolerance=&quot;1e-7&quot; "
-------------------------------------------------------------------------------------------------
Also is it possible to change the value of the properties in the same
perl program after it is extracted using the parser/lexer ? I would
like to allow a user to see the above output for all the nodes in the
file , then modify the Value property (if needed).
If there is any modification i will rename the file along with the
modification time in the filename so the original file is left
untouched.
I have a feeling am going overboard with all these requests..but its
just an idea i had in mind which i want to implement.. I request you to
kindly help me out with your ideas and suggestions.
Thankyou all in advance .
Kitty
 
T

Tad McClellan

for a text
file which has a format similar to an xml file.


If it *is* an XML file, then use an XML parser instead of regexes.

It it is merely _similar_ to one, then we would need to know
it what ways it could differ.

A clear understanding of what data may appear is essential
to writing the code.


[ snip input and output data ]



Also?

You have not asked a question up to this point.

Did you mean to ask a question?

Is there something that you are stuck on?

What have you tried?

I request you to
kindly help me out with your ideas and suggestions.


Show us the code you have so far, and we will help you fix it.

Have you seen the Posting Guidelines that are posted here frequently?
 
K

kitty

Hi
Iam sorry for not posting my query in proper format..
i had put the "xmlish" code right below my intro..and i shall paste it
here again..also i had mentioned how i would like the output to be...

"xmlish" FILE
-------------------------------------------------------------------------------------------------------------------------------------
<GRAPH NAME="471138343152490055" VERSION="V3.0" APP_VERSION="2.7.2.8">
<NODE GUID="471138342839500090" TYPE="######"/>
<PROP GUID="471138342839500090" NAME="Unit" TYPE="Unit Conversion"
ATTRIBUTES="propagates editable !graphical visible !members !required "
SETON="1138343152541" SETBY="kitty" EXPR="On" />
<PROP GUID="471138342839500090" NAME="ODE Solver Settings" TYPE="ODE
Solver Settings" ATTRIBUTES="propagates editable !graphical visible
!members !required " SETON="1138343152549" SETBY="kitty" EXPR="&lt;E
Parameter_for_how_often_Jacobian_should_be_calculated=&quot;0.001&quot;
The_Rounding_Unit=&quot;1e-16&quot;
Absolute_Error_Tolerance=&quot;1e-15&quot;
Relative_Error_Tolerance=&quot;1e-7&quot; /&gt;" />
....
</GRAPH>
------------------------------------------------------------------------------------------------------------------------------

OUTPUT ( The output should list certain properties of a node..)
--------------------------------------------------------------------------------------------------------------------------------
NODE TYPE = "#######"
PROPERTIES :
NAME="Unit"
Value (EXPR) = "On"
NAME="ODE Solver Settings"
Value =
"Parameter_for_how_often_Jacobian_should_be_calculated=&quot;0.001&quot;
The_Rounding_Unit=&quot;1e-16&quot;
Absolute_Error_Tolerance=&quot;1e-15&quot;
Relative_Error_Tolerance=&quot;1e-7&quot; "
-----------------------------------------------------------------------------------------------------------------------

the "Also" was to continue the sentence after my request for the
output..
i shall post the code once am done reading the xml parsers suggested to
me and incorporating them in my code..i hope it would be easier to help
me out then since you will have a better idea about the problem..
thankyou and sorry for the inconvenience..
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top