doubt on while

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pavanponnapalli
    New Member
    • May 2008
    • 51

    doubt on while

    I have been studying programming perl. There I have come across a code something as below:

    Code:
     while (<FILE>) {
        print if /http:/;
        print if /ftp:/;
        print if /mailto:/;
        # What next?
    }
    Can u please tell me what is FILE there?

    cheers,
    pavan.
    Last edited by eWish; Jun 2 '08, 08:54 PM. Reason: Please use code tags
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    FILE is the file handler for the file that you are reading. When you want to process a file, you have to change/redirect the input stream/ output stream to the file. For this purpose, a file-handle is created when you use open() function.
    Code:
    open(FILE,"data.txt") or die "opening file failed";
    When you assign this file-handle within angular brackets to an array
    Code:
    @data=<FILE>;
    The array would contain entire content of file with each line in file as each element in the array(as '\n' is the default input record separator)
    When you assign it to a scalar, it would contain the first line of file:
    Code:
    $data=<FILE>;
    In your code, while(<FILE>) {} loop will iterate through the file, one line at a time.



    I would suggest you to go through Files and Data

    Comment

    • jeffjustice
      Banned
      New Member
      • Jul 2008
      • 9

      #3
      If you want some basic stuff about files, check [DELETED]

      Comment

      Working...