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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.