1
0

added a test of using either stdin or a file from argv

This commit is contained in:
Stephen M. McQuay 2012-09-07 11:32:18 -06:00
parent 75b8de26b0
commit 84d5063722

29
stdin-or-argv/go.go Normal file
View File

@ -0,0 +1,29 @@
package main
import (
"fmt"
// "io"
"io/ioutil"
"log"
// "bufio"
"os"
"strings"
)
var usage = "usage: splitter [file]"
func main() {
var of *os.File
var err error
if len(os.Args) == 2 {
filename := os.Args[1]
of, err = os.Open(filename)
if err != nil {
log.Fatal(err)
}
} else {
of = os.Stdin
}
b, err := ioutil.ReadAll(of)
fmt.Printf("%v\n", strings.Fields(string(b)))
}