gogoglou has asked for the wisdom of the Perl Monks concerning the following question:
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"; # } #
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: probably stupid mistake
by toolic (Bishop) on Apr 01, 2011 at 13:41 UTC | |
by gogoglou (Beadle) on Apr 01, 2011 at 13:52 UTC | |
by toolic (Bishop) on Apr 01, 2011 at 13:58 UTC | |
by SriniK (Beadle) on Apr 01, 2011 at 14:14 UTC | |
by gogoglou (Beadle) on Apr 01, 2011 at 14:03 UTC | |
by gogoglou (Beadle) on Apr 01, 2011 at 14:07 UTC | |
| |
|
Re: probably stupid mistake
by Popcorn Dave (Abbot) on Apr 01, 2011 at 20:26 UTC | |
|
Re: probably stupid mistake
by GrandFather (Saint) on Apr 02, 2011 at 22:53 UTC |