Mirco Wahab wrote:
>
> Needs some more thinking (will look
> at it today on evening again
As Abigail mentioned in another post,
Perls Regexes allow code assertions,
so this task isn't too hard.
The following should work as
poor-mans wc
[wc.pl] ==>
use strict;
use warnings;
my %wc = (lines=>1, words=>0, chars=>0);
my $re = qr/ \b (?{ $wc{words} += 0.25 })
| \n (?{ $wc{lines} ++ })
| . (?{ $wc{chars} ++ })
/x;
my $text = do { local$/; <> };
print map "$wc{$_} $_, ", keys %wc
if () = $text =~ /$re/g;
<==
Regards
M.