http://qs321.pair.com?node_id=248932

YAFZ has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks,

I have 2 small Perl programs which are intended to calculate the same thing, namely the character count in a text file. By character, I mean, any character except blank space and/or tabs.
The first version is something like that:

ccount.pl
=====================================
#!/bin/perl -w while (<>) { chomp; $line = join('', split /[ \t]*/); print $line; }

And the second version is like that:

ccount2.pl
===================================
#!/bin/perl -w while (<>) { chomp; $line += split /[ \t]*/; } print $line;

I use ccount.pl like that:

$ ./ccount.pl <ccount.pl | wc 0 1 69

And I use ccount2.pl like that:

$ ./ccount2.pl <ccount.pl Use of implicit split to @_ is deprecated at ./ccount2.pl line 5. 72

As you see, ccount.pl combined with wc command tells me that the text file consists of 69 while the ccount2.pl by itself is reporting the same file has 72 characters.

Why do I get different number of characters?