Your file "open mode" is wrong, use '<' for read-only.
#!/usr/bin/perl -w
use strict;
my @words;
open FILE, "<", "input.txt" or die "unable to open input.txt $!";
print "file loaded \n";
while (<FILE>)
{
@words = split(' ', $_);
push @all_words, @words;
}
foreach $word (@words)
{
print "$word\n";
}
__END__
# if you want to count the words
# then that is different - use a hash
# table of "word => count"
#the default split (/\s+/,$_)
#differs only between this special case split(' ',$_)
#in how it handles a "null" field at the beginning of the line
my %words;
while (<FILE>)
{
my @words = split;
foreach my $word (@words)
{
$words{$word}++;
}
}
=== or ===
my %words;
while (<FILE>)
{
foreach my $word (split)
{
$words{$word}++;
}
}
==== or ===
my %words;
while (<FILE>)
{
$words{$_}++ foreach (split);
}