in reply to How can I use regex to copy each word of a string into a hash?
If you need a count, you could do this:my $sentence = 'This is a test'; my %hash = map { $_, 1 } ($sentence =~ /\w+/g);
my $sentence = 'This is a test'; my %hash; for ($sentence =~ /\w+/g) { $hash{ $_ }++; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How can I use regex to copy each word of a string into a hash?
by cei (Monk) on Jan 16, 2001 at 23:42 UTC |