in reply to find a string a certain number of times

I think this is better for beginners :
use strict; my $count; my @array; open FILE, "filename"; while (<FILE>){ push @array, $_; } foreach $a(@array){ if ($a =~ m/whatever/ ) { $count ++; } } print $count,"\n";
basic perl stuff ... no need to get crazy ... yes , you do not need the array, if you are only counting. Your regular exp may need some fussing, but that's the fun. Cheers

Replies are listed 'Best First'.
Re^2: find a string a certain number of times
by Roy Johnson (Monsignor) on Jan 30, 2005 at 12:55 UTC
    while (<FILE>){ push @array, $_; }
    is generally written
    @array = <FILE>;

    Caution: Contents may have been coded under pressure.