What’s a simple way to implement file inclusion in Ruby, e.g. if a text file includes {{{stuff.txt}}}, the contents of stuff.txt is included in-line. I thought maybe something like this:
cat prog | ruby -pe 'gsub /{{{.+}}}/, File.open("$0").read'
… with eval() involved, but can’t get it to work.
If you’d like to do it straight from the command line, try
As pointed out by Alex D,
.+is greedy and matches as many characters as it can. On the other hand,.+?tries to match as few characters as possible.Ruby’s command line
-pexpects you to update the value of the$_variable. Hence usage of mutatinggsub!instead ofgsub, which makes a copy. The same result could be achieved by using-n.