while
while
-
The while loop also performs iteration and in CGI
scripts is primarily for reading lines in a file. The while loop can be
used to read and print out every line of a file with the following syntax:
open ([FILE_HANDLE_NAME], "[filename]");
while (<[FILE_HANDLE_NAME]>)
{
print "$_";
}
close ([FILE_HANDLE_NAME]);
The script would print out every line in the file "filename" because the
"$_", the Perl "default" variable, represents "the current line" in this
case.
The process of opening and closing files is covered
in the "File Management" section
later. |
Additional Resources:
foreach
Table of Contents
for Loops
|