http://qs321.pair.com?node_id=402686


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

There is a bug, @words ends up only containing the "words" in the last line ;-) as you are resetting it for each line.

Also there was no need for two splits, just one is good enough, and better use strict ;-)

use Data::Dumper; use strict; use warnings; open FILE, "a.txt"; undef $/; $_ = <FILE>; close(FILE); my @words = split; print Dumper(\@words);