in reply to grep and array
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:my $hold2 = join "|", @hold2; `egrep -wn '$hold2' nbsssbs//esel/bld/*.bld nbsssbs/sbc/bld/*.bld nbss +bts/btsc/bld/*.bld > $temp/otherblds2.txt `;
Now your desired data should be in @otherblds. That gives us: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.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;
Makeshifts last the longest.
|
|---|