I have this script in which I am trying to clean up the tmp file output and use only arrays and variables.
It does work, I created it a while back.
open 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;
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 output
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;
Does anyone have suggestions?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.