develooper Front page | perl.beginners | Postings from May 2003

Re: count of words (fields) after "split"

Thread Previous | Thread Next
From:
John W. Krahn
Date:
May 31, 2003 12:29
Subject:
Re: count of words (fields) after "split"
Message ID:
3ED90270.5736E106@acm.org
Richard müller wrote:
> 
> Hi,

Hello,

> I'm a very newbie with perl. I have a text file and want to read it line
> by line and split it into words:

It depends on how you define "words".


> my @fields = split / /, $_;
> - so far no problem.

Are you sure?  Using "split / /, $_" does not do what you seem to think
it does.  Better to use split with no arguments.

my @fields = split;


> Now I have to count the words in the line. This I could not achieve.
> I#m sure it is very simple - but I did not find the suitable command

my $count = @fields;


John
-- 
use Perl;
program
fulfillment

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About