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 |
In Section
Seekers of Perl Wisdom