
BillKSmith
Veteran
Apr 11, 2014, 5:25 AM
Post #2 of 2
(2479 views)
|
Re: [PerlBeginner31] Concatenating patterns and finding the number of occurences
[In reply to]
|
Can't Post
|
|
Your inner loop runs twice for each match. (Once for the HE... and once for the i)
use strict; use warnings; #open FILE, "SAMP.txt" or die $!; *FILE = *DATA; my %hash; while (<FILE>) { foreach ( /(HE(?:Y|LLO)i)/g ) { $hash{$_}++; } } foreach my $key ( keys %hash ) { print "$key: $hash{$key}\n"; } __DATA__ HEYi dfjhfk HEY HEYi HEYi HEYi HELLOi HELLOi HELLOi HELLOi HELLOi Good Luck, Bill
|