150

Input/Output
Input in List Context

  • To read all available lines from an input stream, enclose the file handle in < > simbols and assign the result to a list variable

  • Given the input

      Hello
      World

  • All lines can be read with one statement as follows

      @lines = <FILEHANDLE>; # Yields ( "Hello\n", "World\n" )

  • Reading the contents of an entire text file typically looks like this

      open( FILEHANDLE, "<myFile.txt" );
      chop( @lines = <FILEHANDLE> );
      close( FILEHANDLE );