You're using an awfully complicated method to pick the desired filenames.. The following will suffice: my @hold2 = map /(\w+\.bld)/, <OUTother>; Note however that egrep expects only a single, first argument to be an expression to search for. So it interprets the array elements of @hold2 other than the first one as names of files to examine.. what you want to do is to construct a regex:
my $hold2 = join "|", @hold2; `egrep -wn '$hold2' nbsssbs//esel/bld/*.bld nbsssbs/sbc/bld/*.bld nbss +bts/btsc/bld/*.bld > $temp/otherblds2.txt `;
Which you can roll into the map at the top. That makes: my $hold2 = join "|", map /(\w+\.bld)/, <OUTother>; But why use backticks when you're throwing the program's output away anyway? system "egrep -wn '$hold2' nbsssbs//esel/bld/*.bld nbsssbs/sbc/bld/*.bld nbssbts/btsc/bld/*.bld > $temp/otherblds2.txt" or die "egrep failed: $!"; Since you're outputting the results to a file in a tempdir, I suspect you go on to read them back in later - that would be an awfully roundabout way of doing what you want. Instead, you can open a pipe to it:
open EGREP, "egrep -wn '$hold2' nbsssbs//esel/bld/*.bld nbsssbs/sbc/bl +d/*.bld nbssbts/btsc/bld/*.bld |" or die "Pipe to egrep failed: $!"; my @othersblds = <EGREP>; close EGREP;
Now your desired data should be in @otherblds. That gives us:
open(OUTother, "<", "C:/Perl/MyScripts/tmp.txt") or die "Couldn't open + file: $!"; my $hold2 = join "|", map /(\w+\.bld)/, <OUTother>; close OUTother; open EGREP, "egrep -wn '$hold2' nbsssbs//esel/bld/*.bld nbsssbs/sbc/bl +d/*.bld nbssbts/btsc/bld/*.bld |" or die "Pipe to egrep failed: $!"; my @othersblds = <EGREP>; close EGREP;
Of course if you really do want the tempfile, use the system call instead.

Makeshifts last the longest.


In reply to Re: grep and array by Aristotle
in thread grep and array by amoura

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.