in reply to Re: Word Counting
in thread Word Counting

This definately isn't homework, heh...sometimes I wish I were still in school though. I know how to open and read files, but I don't understand part #3. How do I split on whitespace? You'd have to split each word into their own variable, that's the part I don't understand.

Replies are listed 'Best First'.
Re[3]: Word Counting
by Tanalis (Curate) on Apr 24, 2003 at 20:59 UTC
    You can use split to put the words into an array or a list:
    my $line = "This is a line of text"; my @words = split /\s+/, $line;
    Note that the /\s+/ bit technically isn't needed, because split defaults to splitting on whitespace.

    There's more info on split on Perldoc.

    Hope that helps,
    -- Foxcub
    A friend is someone who can see straight through you, yet still enjoy the view. (Anon)

Re: Re: Re: Word Counting
by perlplexer (Hermit) on Apr 24, 2003 at 20:58 UTC
    Use split(); e.g.,
    # Assuming %words is the hash where you keep all the words $words{$_}++ for split /\s+/, $line;
    --perlplexer