Didnt i do that with <FILE> or is it without the FILE? The file is to come from STDIN What do the <> means?

<> is a special case of <FILE>

With <FILE>, the input comes from only that file handle. With <>, input comes from STDIN if there are no command-line arguments. If there are command-line arguments, each is considered to be a file, it is opened in its turn and becomes the input.

while( <FILE> ) will work. It assigns each line of input to the variable $_. To assign it to another use: while( my $line = <FILE> )

[13818160@lab219-02 wk8]$ perl wordCount.pl Welcome to the File Word Count program Enter the name of the file to open words.pl Use of uninitialized value in print at wordCount.pl line 14, <FILE> line 1. Use of uninitialized value in string eq at wordCount.pl line 15, <FILE> line 1. 0

[13818160@lab219-02 wk8]$ perl wordCount.pl Welcome to the File Word Count program Enter the name of the file to open words.pl Use of uninitialized value in print at wordCount.pl line 14, <FILE> line 1. Use of uninitialized value in string eq at wordCount.pl line 15, <FILE> line 1. 0

Whats wrong?

[also what does the 'my' in front of the variable mean?]

The interior of your loop does not count words, it counts spaces after the first line.

'my' sets the scope of the variable that follows it to the block or file it is contained in. This is called lexical scoping.

Well my way of counting words should work as well and it does in the for loop but not in the while loop which is what i cant seem to get working. before i try your idea, i want to figure out whats wrong with mine?

------------------------------------------------------------------ If some one can do it, we can do it better http://maestriatech.com perl@maestriatech.com --------------------------------------------------------------------

/ / means split the $_ that comes from the above while loop, ie split each line of the file when a space occurs.

Just go ahead and learn a bit more about $_ and split. you will understand better :)

------------------------------------------------------------------ If some one can do it, we can do it better http://maestriatech.com perl@maestriatech.com --------------------------------------------------------------------

------------------------------------------------------------------ If some one can do it, we can do it better http://maestriatech.com perl@maestriatech.com --------------------------------------------------------------------

Open the script in Vi editor, Place the control over the } you have doubt and then press Shift+5 it will show you the other brace that it matches.

------------------------------------------------------------------ If some one can do it, we can do it better http://maestriatech.com perl@maestriatech.com --------------------------------------------------------------------

# I'd need to do a benchmark test, but this is probably the most efficient. my $words = (split /\s+/, `wc $inFileName`)[2]; print "Words:$words\n";

# However, this one doesn't use an external utility. my $count; open my $FILE, '<', $inFileName or die "can't open '$inFileName' $!"; while ( <$FILE> ) { $count++ for split; } print $count,$/;

[edit] In my test, the wc command extracted the count of words, lines, and characters. When I posted, I simply altered the array slice to return only the word count. The command itself could be altered accordingly, if desired.[/edit]