1
'#{File.read("file")}' puts

Does not work. Is it possible to read in the content of a text file in GolfScript?

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
Beatle
  • 43
  • 2

1 Answers1

2

The #{...} expansion only occurs with double-quoted strings:

"#{File.read('file')}" puts

works fine.

However, there are some catches.

  1. If you want 'file' to be a parameter, you have to delay the expansion.
  2. The result is cached the first time, so if you want to read the same file more than once (e.g. to check for changes) you have to ensure that the expanded value changes. The easiest way I know to do this is to expand "#{File.read('file')#1}", "#{File.read('file')#2}", etc.
Peter Taylor
  • 4,918
  • 1
  • 34
  • 59