in reply to Re: problem printing message if search item is not found
in thread problem printing message if search item is not found

Thought it might be helpful to see a rewrite of the code. ;)

Just cleaned up a bit, and added use strict; and use warnings; and a little bit of error handling.
#!/usr/bin/perl use strict; use warnings; my $fsearch = 'file.txt'; open (TEXTFILE, 'c:/perl_programs/' . $fsearch) or die "CAN'T OPEN $fs +earch: $^E\n"; print "Enter a string to search for: "; chomp (my $search = <STDIN>); my @line = <TEXTFILE>; my $count = 0; foreach (@line){ $count++; if ($_ =~ /$search/i) { print "\nLine that matched <$search> found on line #$count\n"; print "$_\n"; } } if (!$count) { print "\nsubstring <$search> NOT found\n"; }