in reply to Counting words
As you have a stream you probably want to use stream parsing logic. Here is an example:
my ( $space, $wc ); my $get_words = 5; while( read(DATA,$_,1) ) { if ( m/\s/ ) { $space = 1; } else { if ( $space ) { print "\n"; $space = 0; $wc++; last if $wc >= $get_words; } print; } } __DATA__ There was an old lady who lived in a shoe
cheers
tachyon
|
|---|