I have the following code.  This code prints a / for each occurance of a certain 
number/word in a file.  How would I change this to print a / for each 5 instances of a 
given word/number?

Thanks

#!/usr/bin/perl 

my $file;
$file = $ARGV[0];
open( "file",  "< $file") or die "Cannot open image file $file\n";
$text = join('', <file>);
%count = ();
for (split(/\s/, $text)) {
 $count{$_} .="/";
 
}

foreach $word (sort keys %count) {
 next unless $word =~ /\d/;
 next if $word =~ /p2/i;
 next if $word =~ /^\#/
;  

 printf("%-05s%s\n", $word, $count{$word});

}


Reply via email to