Hi, I have 2 short arrays with only words in them. I want to check if a word in the first array occurs in the second array, but I am having some problems.
#!/usr/bin/perl -w use strict; use warnings; use utf8; open (INPUT, "<:utf8", "short.txt") or die "can't open"; open (INPUT2, "<:utf8", "woordelysEng.txt") or die "can't open"; open (OUTPUT, ">output.txt") or die "can't open"; my @words; my @EN; while (<INPUT>) { my $word = $_; chomp $word; @words = split(/ /, $word); } while (<INPUT2>) { my $word = $_; chomp $word; @EN = split(/ /, $word); } for(my $z = 0; $z <= $#EN; $z++) { for(my $y = 0; $y <= $#words; $y++) { if($EN[$z] eq $words[$y]) { print OUTPUT "$EN[$z]\n"; } } } for(my $z = 0; $z <= $#EN; $z++) { foreach my $correct(@words) { if ($EN[$z] eq "$correct") { print "$EN[$z]\n"; } } }
I tried 2 different ways of looping through it but without success. Any advice? Here is the 2 text files:
short.txt- the cat ran up the tree the cat the dog then barked at the cat
the cat jumped out of the treewoordelysEng.txt- the cat dog
It does not print anything to the output file.
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |