Hi Perl Monks!
I'm trying to use array elements in a file search. This is what I've written thus far. I want the script to be able to go through each array element and then search for that particular element in a file. My logic (to me) seems right, but I feel that I'm missing a fundamental concept.
This is the infile.
This is the code.
my @array = qw (A B C D);
open (my $INFILE,"<", "letters");
open (my $OUTFILE,">", "capturedletters");
foreach my $i (@array)
print "Foreach loop$i, ";
print "While loop$i, "; #this variable does not change
if ($_ =~/^$i/)
print $OUTFILE "$_";
This is the output I get.
While loopA, While loopA, While loopA, While loopA, Foreach loopB,