[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Word Count Programme..



Hah! what was I thinking! Replace line 13 with

   $charcount += length($_);

Is my face red.

A.L.

>-------------------
>#!/usr/bin/perl -lw
>
>use strict;
>
>my $filename = 'sample.txt';
>my ($charcount, $wordcount, $linecount) = (0,0,0);
>
>open(F, $filename)
>   or die "Error opening $filename: $!";
>
>use locale;
>while (<F>) {
>   $charcount += () = /./gs; # newline counts as a character
>   $wordcount += () = /\w+/g;
>   $linecount++;
>}
>no locale;
>
>close F;
>
>print "Characters:  $charcount";
>print "     Words:  $wordcount";
>print "     Lines:  $linecount";
>__END__




***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch