Interestingly enough, the file is never opened.

The reason is that the external program 'grep' is opening the file itself.

Any reason that the grep line is enclosed in ``?

Backticks (``) run an external program, like the grep here.

My suggestion was to not use backticks at all, as Perl is perfectly capable of doing grep-like jobs all by itself...  and probably a lot faster, too, than when calling the external grep multiple times.  Of course, you'd have to restructure the program accordingly...

AFAICT, the consecutive runs of grep (in combination with the use of the temp files) achieve to extract lines where all the tested conditions match.  A restructured solution without using grep could look something like this:

... LINE: while (<$fh>) { if ($aquiSW =~ /New Stuff/i) { next LINE unless /1$/; } if ($lA && $Artist ne ".*") { next LINE unless /^\Q$Artist/i; } if ($lL && $Label ne "*") { next LINE unless /\|\Q$Label/i; } # ... if ($lT && $Title ne "*") { # split $Title into @words... for my $word (@words) { next LINE unless /\Q$word/i; } } # ... # we only get here if all the tested conditions matched print; }

In reply to Re^3: Online GREP problem by almut
in thread Online GREP problem by gfausel

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.