Hi novice2015,
I don't think in-memory files like you are trying to use here are necessary, they overcomplicate the solution. Just use a normal Perl array to hold the data in between loops.
What is unclear to me is this: If you don't want to use any of the files in /tmp, where will the data that you are currently reading from /tmp/bpl.txt and /tmp/lst.txt come from? In order to answer your original question, I could assume the data you are reading from those two files is available in @words and @data, respectively. Then I can answer the original question and rewrite your original script like so:
# get @words and @data from somewhere my $pattern = join '|', @words; my @lines; for (@data) { push @lines, $_ if /$pattern/; } # do something with @lines
By the way, are you using warnings and strict? In your original code you wrote open my $bpl_fh, ... but then close $bplist_fh;. Also, in your later posts it looks like you're closing $bpfh1; too soon, inside the loop, which should give you a warning. So always Use strict and warnings!
Now, if I understand your later posts, you then want to take the lines that you've previously matched with /$pattern/ and stored in @lines and operate on those. If I take your code from here and rewrite it, I get:
for (@lines) { my @fields = split /,/; if ( $fields[2] eq '1' || $fields[2] eq '0' ) { print "THESE ARE THE>>$fields[4]\n" if /MONTHLY/ && !/,-,/; } }
But then my question is, do you need @lines at all? You could skip the creation of that array and do:
my $pattern = join '|', @words; for (@data) { next unless /$pattern/; my @fields = split /,/; if ( $fields[2] eq '1' || $fields[2] eq '0' ) { print "THESE ARE THE>>$fields[4]\n" if /MONTHLY/ && !/,-,/; } }
If you have further questions, I strongly recommend you read Short, Self Contained, Correct Example and How do I post a question effectively? - without input data, runnable code, expected output or exact error messages, it's a guessing game.
Hope this helps,
-- Hauke D
In reply to Re: removing the need for tmp files from script
by haukex
in thread removing the need for tmp files from script
by novice2015
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |