Hi perlmonks, nice to meet you. I am practicing my regexes and want to know how many times a word in a string occurs but i am not succeeding. However i did wrote a working example but not by using a regex. Here it is:
use strict; use warnings; my %hash=(); my $re = "iowq john stepy andy anne alic bert stepy anne bert andy ste +p alic andy"; my @names = split(/\s+/,$re); foreach(@names) { $hash{$_}++; } foreach(keys %hash) { print "key: $_ value: $hash{$_} \n"; }
Can someone show me a regex to do all this?
In reply to counting words in string by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |