Hello,

I don't have any idea in Perl, but I need to do

something, so I have started learning PERL.

The requirement for me is given below.

I have 2 files.

File1

==============

module and_1 (y,a,b); input a, b; output y; and x1 (y,a,b); if ( a == b) y = 1'b0; else y = 1'bx; if ( a == 1 ) y = 1'b1; else y = 1'b0; endmodule
module or_1 (y,a,b); input a, b; output y; or x1 (y,a,b); if ( a == b) y = 1'b0; else y = 1'bx; if ( a == 0 ) y = 1'b0; else y = 1'b1; endmodule

=================================

FILE2

==============

module and_1 (y,a,b); input a, b; output y; and x1 (y,a,b); if ( a == b) y = 1'bx; else y = 1'b0; if ( a == 0 ) y = 1'bx; else y = 1'b1; endmodule module or_1 (y,a,b); input a, b; output y; or x1 (y,a,b); if ( a == b) y = 1'b1; else y = 1'b0; if ( a == 0 ) y = 1'bz; else y = 1'bx; endmodule

====================

Now I need to parse FILE1, FILE2. Get some STRINGS from

FILE2 and replace them in FILE1 and write it down in FILE3.

The followings steps need to do.

Search for keyword "module". Both FILE1 and FILE2 has module

and_1, or_1. FILE_1 => "module" must be mapped with FILE_2

=> "module".

Now "and" rplaced by "nand" and "or" replaced by "xor" ( I

was able to do this),

After then it will search "if" keyword and the corresponding

condition in FILE1 and will map that from FILE2 and what

ever next line in FILE2 has will be replaced by that in

FILE1. So FILE3 will be look like this.

FILE3

===========

module and_1 (y,a,b); //not changing anything input a, b; output y; nand x1 (y,a,b); //and changed to nand if ( a == b) // searching for "if ( a == b)" y = 1'bx; // replaced condition "y = 1'b0;" in FILE1 with "y + = 1'bx;" from FILE2 else y = 1'b0; // similarly from the upper if ( a == 1 ) y = 1'bx; else y = 1'b1; endmodule module or_1 (y,a,b); input a, b; output y; xor x1 (y,a,b); if ( a == b) y = 1'b1; else y = 1'b0; if ( a == 0 ) y = 1'bz; else y = 1'bx; endmodule

===========================

Your help really needed for me.

Thanks


In reply to Read conditional strings from a file, search and replace same string in another file in perl by anirbanphys

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.