
King Norre
Novice
Apr 15, 2003, 6:07 AM
Post #1 of 7
(577 views)
|
|
A question about a sample script.
|
Can't Post
|
|
Hi, I'm learning Perl using the book "Teach yourself Perl5 in 21 days" from David Till. Somewhere in the book there's the following sample script: #!/usr/bin/perl # a word-counting program that uses the NEXT statement $total = 0; while ($line = <STDIN>) { $line =~ s/^[\t ]*//; $line =~ s/[\t ]*\n$//; next if ($line eq ""); @words = split(/[\t ]+/, $line); $total += @words; } print ("The total number of words is $total\n"); ---------- END Normally the input should end when I press CTRL + D. However, when I run the script I can only put in 1 line. When I press ENTER I get the following error message: Split loop at ./ex8.11 line 9, <STDIN> line 1. I have absolutely NO idea what could be wrong. Can anyone help me? Thanks in advance, KN
|