Help to parse text file

Discussion in 'Perl Misc' started by kitty, Feb 8, 2006.

  1. kitty

    kitty Guest

    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
     
    kitty, Feb 8, 2006
    #1
    1. Advertising

  2. kitty <> wrote:


    > 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



    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?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 9, 2006
    #2
    1. Advertising

  3. kitty

    kitty Guest

    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..
     
    kitty, Feb 9, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John M. Lembo

    Parse Text File and Output to File

    John M. Lembo, Aug 1, 2003, in forum: Perl
    Replies:
    0
    Views:
    12,759
    John M. Lembo
    Aug 1, 2003
  2. Sacha Korell
    Replies:
    2
    Views:
    15,122
    Mattias Sjögren
    Sep 6, 2003
  3. Replies:
    19
    Views:
    1,191
    Daniel Vallstrom
    Mar 15, 2005
  4. John M. Lembo

    Parse Text File and Output to File

    John M. Lembo, Aug 1, 2003, in forum: Perl Misc
    Replies:
    2
    Views:
    181
    JS Bangs
    Aug 1, 2003
  5. Zhen Zhang

    parse a csv file into a text file

    Zhen Zhang, Feb 6, 2014, in forum: Python
    Replies:
    29
    Views:
    159
    Tim Chase
    Feb 6, 2014
Loading...

Share This Page