http://qs1969.pair.com?node_id=402673


in reply to How do you place words from a sentence into an array?

As everybody else pointed out, split will save you ;-)

What I want to add is, to use hash instead of array in this case. Why not go one step further and make your exercise more meaningful, and think about better data structure.

The benefit of using hash is so that you can count the frequency of each word:

use Data::Dumper; use strict; use warnings; my $words; while (<DATA>) { for (split) { $words->{$_} ++; } } print Dumper($words); __DATA__ three blind mice three blind mice see how they run