now can also read from stdin

This commit is contained in:
Erik Brakkee 2024-11-20 21:29:35 +01:00
parent 8a2c4757b9
commit 18d362c926

View File

@ -68,9 +68,16 @@ func main() {
os.Exit(1) os.Exit(1)
} }
filename := os.Args[1] filename := os.Args[1]
var file *os.File
file, _ := os.Open(filename) if filename != "-" {
defer file.Close() file, err := os.Open(filename)
if err != nil {
panic(err)
}
defer file.Close()
} else {
file = os.Stdin
}
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
lineno := 0 lineno := 0