Jeri has asked for the wisdom of the Perl Monks concerning the following question:
This is the infile.
#INFILE A B C D
This is the code.
#!usr/bin/perl5.8.8 use strict; use warnings; my @array = qw (A B C D); open (my $INFILE,"<", "letters"); open (my $OUTFILE,">", "capturedletters"); my $Letter; foreach my $i (@array) { print "Foreach loop$i, "; print "\n"; while (<$INFILE>) { print "While loop$i, "; #this variable does not change if ($_ =~/^$i/) { print $OUTFILE "$_"; } } } close ($INFILE); close ($OUTFILE);
This is the output I get.
Thanks!Foreach loopA, While loopA, While loopA, While loopA, While loopA, Foreach loopB, Foreach loopC, Foreach loopD,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using array elements for a file search
by jwkrahn (Abbot) on Oct 24, 2011 at 20:04 UTC | |
|
Re: Using array elements for a file search
by onelesd (Pilgrim) on Oct 24, 2011 at 20:07 UTC | |
|
Re: Using array elements for a file search
by mrstlee (Beadle) on Oct 25, 2011 at 11:44 UTC | |
by Anonymous Monk on Oct 25, 2011 at 11:46 UTC | |
by Diffie (Initiate) on Jun 26, 2012 at 13:54 UTC | |
|
Re: Using array elements for a file search
by Anonymous Monk on Oct 24, 2011 at 23:59 UTC | |
by Jeri (Scribe) on Oct 25, 2011 at 14:27 UTC |