in reply to putting text into array word by word
#!usr/bin/perl -w use strict; open FILE, '<', "input.txt" or die "unable to open input.txt"; # the $! variable adds the O/S specific info, but it is not # not always that useful. my @all_words; while (<FILE>) { my @these_words = split(' ', $_); foreach my $this_word (@these_words) { push @all_words, $this_word; } }
#to count the words: use Data::Dumper; my %words; while (<FILE>) { my @these_words = split(' ', $_); foreach my $this_word (@these_words) { $words{$this_word}++; } } print Dumper \%words;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: putting text into array word by word
by Anonymous Monk on Jan 09, 2012 at 18:31 UTC | |
|
Re^2: putting text into array word by word
by jms53 (Monk) on Jan 09, 2012 at 18:50 UTC | |
by Marshall (Canon) on Jan 09, 2012 at 19:05 UTC |