in reply to find a string and count of its occurence in a text file
Doing this way you will never load all the file lines but parse one by one.open FILE, $file or die "can't open $file: $!\n"; while(<FILE>) { next unless /^abc:/; $counter++; chomp; print "$line\n"; # whatever you need } close FILE;
Oha
PS: perl have the poetry of next unless, which is so beauty instead of if(! COND) { continue } I can't avoid posting it! :)
|
|---|