in reply to problem printing message if search item is not found
is executed outside the loop. So it will print the message always, except for the case when the last line contains the searchword. You have to use a flag.if (!($_ =~ /$search/)) { print "\nsubstring <$search> NOT found\n"; }
my $found; my $counter; for (@line) { $counter++; if ($_ =~ /$search/i) { print "\nLine that matched <$search> found on line $counter\n"; print "$_\n"; $found++; } } if ( $found ) { print "$count found words total\n"; } else { print "\nsubstring <$search> NOT found\n"; }
|
|---|