in reply to Perl script to Parse a file for a string

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