Hi All,

Before asking my question, i have to say this....Perlmonks is really a great resource for the beginner in perl, i am really thank full to all for your kind replies.

I have a file "file1" with three lines as follows

c_c b_c a_c

I have another file "file2" with following lines

enable_pad : INBUF port map (PAD => enable, Y => enable_c); c_pad : INBUF port map(PAD => c, Y => c_c); b_pad : INBUF port map(PAD => b, Y => b_c); sum_pad : OUTBUF port map(D => sum_c, PAD => sum); VCC_i_0 : VCC port map(Y => VCC_0); VCC_i : VCC port map(Y => \VCC\); Sum_O : XOR3 port map(A => b_c, B => a_c, C => enableandc, Y => sum_c) +; carry_pad : OUTBUF port map(D => N_5, PAD => carry); a_pad : INBUF port map(PAD => a, Y => a_c); GND_i_0 : GND port map(Y => GND_0); GND_i : GND port map(Y => \GND\); Carry_O : MAJ3 port map(A => a_c, B => enableandc, C => b_c, Y => N +_5); modify : XOR2 port map (A=> c_c, B=> enable_c, Y => enableandc);

i want a perl script that reads file2 and print the lines which has any of the words listed in file1 (i.e. either a_c or b_c or c_c) and save those lines in new file.

My perl code for this is as follows

use strict; use warnings; open (F1, "<new4.txt") or die; open (F2, ">new5.txt") or die; while (<F1>) { open (F3, "<new3.txt") or die; my $lines = <F3>; print F2 if (/$lines/); close (F3); } close (F1); close (F2);

But, its not copying any of the matched lines in new5.txt file.

Please correct the mistake....Thank you all once again...


In reply to How to read the regular expression from another file? by sumathigokul

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.