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


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

open FILE, "bingo_in.txt"; undef $/; $file = <FILE>; @lines = split /\n/, $file; for (@lines ) { @words = split; }

TIMTOWTDI

--Prasad

Replies are listed 'Best First'.
Re^2: How do you place words from a sentence into an array?
by pg (Canon) on Oct 26, 2004 at 16:25 UTC

    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);