Earn cash for Clicks! logo

internet.com
Join the free
WDVL newsletter!

home

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

Up to => Home / Authoring / Scripting / Tutorial

Instantly look up a "techie" word using Webopedia!!


internet.com
e-commerce
WebDeveloper Network



Copyright 1999 internet.com Corporation. Legal Notices. Privacy Policy.

www.internet.com