untested
use strict; use warnings; open (IN, 'myfile.txt') or die $!; my @lines = <IN>; my $cnt = 0; for my $line (@lines) { if ($line =~ /somekeyword/) { $cnt++; } } print ("somekeyword was found in $cnt lines\n");
You could shorten this code a LOT but wanted to make it a little more explicit.
NOTE: You don't have to necessarily put the whole file in an array. You can use while(<IN> and check that way too.
In reply to Re^3: find text in string
by sk
in thread find text in string
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |