in reply to word boundary match problem
Change the first while to a foreach and remove the angle brackets from around @source and it'll work.
#!/usr/bin/perl -w use strict; open (SOURCE, '<', 'test.txt') || die "Can't open test.txt: $!"; my @source = <SOURCE>; close (SOURCE); my $size=0; foreach(@source){ $size++ while m{\b\w+\b}g; } print "wordcount: $size words\n";
|
|---|