in reply to find a string and count of its occurence in a text file
open my $file, 'in.txt' || die "Couldn't open file: $!\n"; #better +way to make file handles foreach (<$file>){ #for each line push @matches, $_ if (/abc/); #keep them in an array if they ma +tch } print @matches; #print the matches print "Total matches: ",scalar(@matches),"\n"; #print the number of + matches
|
|---|