Others have suggested far better ways.

However, in light of your repeated notes that you really want only a mod to your existing sub:

#!/usr/bin/perl -w use strict; use 5.016; # 1088912 my @args=@ARGV; find_string(@args); # mod of OP's original: sub find_string { my $file = shift; my $string = shift; open my $fh, '<', $file; while ( <$fh> ) { if ($_ =~ /\Q$string/) { warn "Test result is FAIL (i.e. $string is present in $file) +"; } else { if ($_ !~ /\Q$string/) { say "\t Did NOT find $string in $_"; } } } }

But your statement (" Most of my scripts use that function") and request that we give you a modification rather than a different approach puzzles me: I don't see why modifying your existing code in multiple scripts creates less workload than replacing it -- in the same number of scripts -- with something including the improvement for which you asked.


Come, let us reason together: Spirit of the Monastery

In reply to Re: Perl script to Parse a file for a string by ww
in thread Perl script to Parse a file for a string by user786

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.