in reply to Re^2: find text in string
in thread find text in string
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.
|
|---|