Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Trying to generate an output that says something like this for each word occurence:#!/usr/bin/perl $wordcount=0; $line = <STDIN>; chomp($line); WHILE ($line ne "") { @array=split(/ /, $line); for ($i=1; $i<@array; i++) { print $i; } if ( @array =~ /^and/gi) { $wordcount += @array; } $line= <STDIN>; } print("Total number of works is $wordcount \n");
The word and occurred in Line 1 as the 7th word The word and occurred in Line 1 as the 11th word
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: tracking words in lines
by davido (Cardinal) on Nov 12, 2004 at 19:13 UTC | |
by sulfericacid (Deacon) on Nov 12, 2004 at 19:22 UTC | |
by davido (Cardinal) on Nov 12, 2004 at 19:38 UTC | |
by sulfericacid (Deacon) on Nov 12, 2004 at 19:46 UTC | |
|
Re: tracking words in lines
by sulfericacid (Deacon) on Nov 12, 2004 at 18:57 UTC | |
|
Re: tracking words in lines
by TedPride (Priest) on Nov 12, 2004 at 20:41 UTC |