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

Hi! I am a beginner to PERL i want to parse two files and find out the differences.... these are not text files but data files kindly suggest

Replies are listed 'Best First'.
Re: Parsing A File
by tinita (Parson) on May 06, 2004 at 10:58 UTC
    you really gave too little information, so may Text::Diff or Algorithm::Diff be helpful for you. if not, you have to describe how your file(s) look like.
      below mwntioned is the format of my file the values of capacitances and trasition will change .... the actual file is a huge one so it will be asy if it is parsed ..... the desires output is to have the exact name of the module : net : and gate where the change has taken place. thanks for your help regards

      theorbtwo: Added code and readmore tags.

        the desires output is to have the exact name of the module : net : and gate where the change has taken place.

        What change? Without knowing which values you are trying to compare, I can't offer a complete solution.

        Ah, you have two files that you want to compare. Ok. So you turn each one into a data structure, then iterate over one, and report differences against the other.

        Just turning the format you give into a data structure is easy. Although, if the actual input is as large as you say it is, note that this might not be the right answer. If this simulation takes a substantial part of your computer's memory when done in C, trying to create a Perl data structure for the entire output will likely fail. Picking just certain gates should be ok, though.

        Here's the basic pattern you want to follow. Each line is either introducing a new thing to describe, or it is continuing the description of the most recently introduced thing. Either way, we store the description in a data structure (potentially creating a new "slot" if it is a new thing being introduced.)

Re: Parsing A File
by UnderMine (Friar) on May 06, 2004 at 13:15 UTC
    This really depends on what data you are trying to parse and how it is encoded.

    It would be helpful if we knew more, a file specification would be nice ;) about what the data is and why you need the changes.

    If you have no specification as to how the data is stored you will run into trouble interpreting significant and non significant changes.

    ie. databases often store numbers to indicate the length of a string in bytes. If you don't know that then interpreting the following data is very difficult.

    If your data is compressed in any way then it is only worthwhile doing the comparision after decompression otherwise the results are meaningless. If you don't know the compession method you are at a distinct disadvantage, i.e. cracking an unknown compression algorithom is similar to doing cryptographic analysis and is not simple.

    Hope it helps
    UnderMine

Re: Parsing A File
by BUU (Prior) on May 07, 2004 at 07:18 UTC
    Step 1: Learn Perl.

    Step 2: Define problem.

    Step 3: Write code to solve problem.

    Step 4: Test code.

    Step 5: Write code to fix issues found by testing.

    Step 6: Go to Step 4.