(This was the first quiz, in Week 3.)
Grading:
The two versions were similar.
Most people had difficulties. In some cases it was hard to tell if this was because of not understanding the problem. Most people would benefit from retaking the test.
Therefore we'll do the following:
Comments on answers:
myprog < filename
... | myprog
myprog
(with no ``redirection'')
myprog > filename
myprog | ...
myprog
(with no ``redirection'')
So in a pipe prg1 | prg2
the standard output of prg1
becomes
the standard input to prg2
.
Some people mentioned HTML. It's true that a CGI program produces output in HTML, but it's not run from a command line.
myprog arg1 arg2 arg3
These are simply
strings that are passed to the program. They may be file names
or not.
<STDIN>
print
statement.
@ARGV
<>
is special: If there are no
command-line arguments then <>
reads from standard
input. If there are command-line arguments, then <>
treats them as file names and opens and reads the files
one by one. This is not by standard input, though.
In sort filename
or wc filename
, the file name is an
argument, so sort is not reading the file using standard input.