Monday, August 27, 2007

Input/Output :: Handling STDIN and STDOUT

  • Standard in, or STDIN, is the default file handle for reading in text or data streams.
  • Input can be handled like this:
      $input = 
    @linput =
    where $input would store the input line. You can even store STDIN into a list as @linput line shows. You can continuously read in STDIN by:
      while (<>) {
    print $_;
    }
    The above example shows the diamond operator in action. The diamond operator is the shorthand for , and we are printing from the scratch list @_.
  • All prints are directed by default to Standard Out.
  • Perl also provides a STDERR stream.
  • You can use the C functions, sprintf and printf in Perl to format your text! Very powerful!

No comments: