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

Replies are listed 'Best First'.
Re^2: How do you place words from a sentence into an array?
by Diakoneo (Beadle) on Oct 26, 2004 at 16:22 UTC
    Thanks everyone, all your examples helped me think through what I really wanted to do! {Turns to see what the Sage Camel has to say about 'split'.}