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