Skip to content

Instantly share code, notes, and snippets.

@serialhex
Created July 1, 2011 00:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save serialhex/1057637 to your computer and use it in GitHub Desktop.
Save serialhex/1057637 to your computer and use it in GitHub Desktop.
package main
import (
//"./file"
"fmt"
"bufio"
"os"
)
// will initialize dict here...
func loadDict(fname string) []string {
fmt.Print("Loading Dictionary\n")
opn, _ := file.Open(fname)
defer opn.Close()
reader := bufio.NewReader(opn)
theGuess := 10 // the file is ~ this big...
dict := make([]string, 0, theGuess)
// ahh... so much nicer!!
for {
line, _, err := reader.ReadLine()
dict = append(dict, string(line))
if err == os.EOF { break }
}
return dict
}
func main() {
dict := loadDict("tmp")
fmt.Print("printing dict", dict)
}
$ ./social_distance
Loading Dictionary
3
foo<nil> 3
bar<nil> 3
baz<nil> 0
EOF printing dict[foo bar baz ]%
foo
bar
baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment