Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Reading text files

Expand Messages
  • Kai Hintze
    In perl, you read by assigning output from a file pointer to a variable. To read one line at a time assign to a scalar. To read the entire file at once, assign
    Message 1 of 2 , Jun 1, 2000
    • 0 Attachment
      In perl, you read by assigning output from a file pointer to a
      variable. To read one line at a time assign to a scalar. To
      read the entire file at once, assign to an array.

      Ex:

      open(INFILE, "myfile.txt");
      while ($line = <INFILE>) {
      #process line
      }

      print "Please answer: ";
      $answer = <STDIN>;

      - Kai.

      In just two days, tomorrow will be yesterday.


      ________________________________________________
      Get your own "800" number - Free
      Free voicemail, fax, email, and a lot more
      http://www.ureach.com/reg/tag


      ---- On Thu, 1 Jun 2000, =?iso-8859-1?Q?Carlos_S=E1nchez?=
      (listacorreo@...) wrote:

      >
      >
      > I suppose this is a stupid question, but I can manage text
      file reading:
      >
      > I have a file like this:
      >
      > File=myzip.zip
      > Size=189289
      > Desc=This is a very important zip file
      >
      >
      > And I want to read it line by line, and I cannot do this with
      the "read"
      > function (at least directly). Is there any function or way to
      read this
      > text
      > files line by line?
    • Carlos S├ínchez
      ... Thanks, I found other way to do it after sending this message, including the file in an array: open FILE, myfile.txt ; @lines = close FILE
      Message 2 of 2 , Jun 2, 2000
      • 0 Attachment
        > In perl, you read by assigning output from a file pointer to a
        > variable. To read one line at a time assign to a scalar. To
        > read the entire file at once, assign to an array.
        >

        Thanks, I found other way to do it after sending this message, including the
        file in an array:

        open FILE, "myfile.txt" ;
        @lines = <FILE>
        close FILE
      Your message has been successfully submitted and would be delivered to recipients shortly.