Basic HTML version of Foils prepared Sept 20 97

Foil 14 Some Simple Scalar I/O Capabilities

From Tutorial on PERL Computational Science for Information Age Course CPS616 -- Sept 20 97. by Geoffrey C. Fox,Nancy McCracken,Tom Scavo


STDIN is a file handle (or pointer) and <STDIN> is a scalar representing the next line from the input stream
  • $line = <STDIN>; # sets $line to next line read from standard input
Unusually, this line always includes terminating newline and so we have a special function to remove terminating newlines
chomp($line); removes the newline in $line and returns a newline (or not, if none is present)
  • $nl = chomp($line) # set $nl to "\n" and remove newline from $line
  • chop is similar but removes any character (not just newline)
We can also print scalars with print $line;
print is more powerful and we will learn about it later as argument can be a scalar but is normally a list or array



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Sep 21 1997