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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |