#!/usr/bin/perl -wl use strict; my $line1 = "perlmonk perlmonk perlmonk"; my $count1 = () = $line1 =~ /perlmonk/g; my $line2 = "perl m onk p erlmonk per lm onk"; # Remove the spaces and count as before $line2 =~ s/ //g; my $count2 = () = $line2 =~ /perlmonk/g; print for $count1, $count2; __END__ Prints: 3 3
--
John.
In reply to Re: count words in a line
by jmcnamara
in thread count words in a line
by benlaw
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |