Richard Müller wrote:
> Hi,
> 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:
> my @fields = split / /, $_;
> - so far no problem.
> 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
> --
> Richard Müller - Am Spring 9 - D-58802 Balve
> [EMAIL PROTECTED] - www.oeko-sorpe.de

        Is what you split on equivalent to word count? If yes, then scalar(@fields) 
will give you the count.  If what you have in @fields can not at face value be defined 
as a word, then you would need to do:
my $MyWords = 0;
foreach ( @fields ){
        $MyWords++ if ( /[a-z\-_]+/i ); # I say if a-z, hyphen and an underscore and 
we will count
 }                                                # as a word.  If this is not what 
you want, then you need
                                                  # to define what you consider a 
word.  There is \w which is
                                                  # defined as a-zA-Z0-9_   In mine, I 
use i which says ignore
                                                  # case.

A start.
Wags ;)


**********************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************************************


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to