novice2015 has asked for the wisdom of the Perl Monks concerning the following question:
So I have made bpl and bpout into an arrays but I am unsure of how to write the while statement. I want it to perform the same task as the above script but without using the /tmp/files to read from and outputopen my $bpl_fh, '<', '/tmp/bpl.txt' or die $!; chomp(my @words = <$bpl_fh>); close $bplist_fh; my $pattern = join '|', @words; my @lines; open my $fh, '<', '/tmp/lst.txt' or die "unable to open file '$file' f +or reading : $!"; open my $fh2, '>', '/tmp/lst2a.txt' or die "unable to open file '$file +' for reading : $!"; while (<$fh>) { push @lines, $_ if /$pattern/; } print $fh2 "$_\n" foreach @lines; close $fh2;
Does anyone have suggestions?chomp(my @words = @bpl); my $pattern = join '|', @words; #my @lines; my $item; while (@bpout) { my $item = (@bpout); push $item, $_ if /$pattern/; } print "$_\n" foreach $item;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: removing the need for tmp files from script
by hippo (Archbishop) on Jul 22, 2016 at 16:29 UTC | |
|
Re: removing the need for tmp files from script
by Laurent_R (Canon) on Jul 22, 2016 at 17:12 UTC | |
|
Re: removing the need for tmp files from script
by BillKSmith (Monsignor) on Jul 23, 2016 at 22:51 UTC | |
by novice2015 (Acolyte) on Jul 25, 2016 at 21:59 UTC | |
by Cristoforo (Curate) on Jul 25, 2016 at 22:53 UTC | |
by novice2015 (Acolyte) on Jul 29, 2016 at 21:15 UTC | |
by BillKSmith (Monsignor) on Jul 26, 2016 at 12:19 UTC | |
|
Re: removing the need for tmp files from script
by haukex (Archbishop) on Jul 30, 2016 at 14:15 UTC |