dear perl monks. I have the following piece of code which does something really trivial but I do not get any results. So what I want to do is first of all I have one array of keywords and one array of sentences. I want to print the keyword and the sentence if somewhere in the sentence the keyword appears. It was working with one line in each file but as soon as I introduced a second sentence it stopped working. I think that I am doing something really stupidly wrong. Please be kind enough to help me out. Thanks in advance for any help

#!/usr/bin/perl my $filename1 = $ARGV[0]; my $filename2 = $ARGV[1]; open(INPUT, $filename1); open(INPUT2,$filename2); my $line; my @fields1; my $fields1; my $line2; my @fields2; my $fields2; my $i=0; my $line; while ($line =<INPUT>){ chomp $line; $i++; push (@fields1, $line); } while ($line2 =<INPUT2>){ chomp $line2; push (@fields2, $line2); } foreach $fields1(@fields1){ foreach $fields2(@fields2){ # print "$fields1\n"; # print "$fields2\n"; if ($fields2 =~ m/$fields1/){ print "success\n"; } } } # foreach $fields1(@fields1){ # if ($line2 =~m/$fields1/){ # print "$line2\n"; # } # } # } # foreach $fields1(@fields1){ # print "$fields1\n"; # } #

In reply to probably stupid mistake by gogoglou

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.