lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 9/18/07, Thomas A. Schmitz <thomas.schmitz@uni-bonn.de> wrote:
> Wow, that was fast! Thanks so much, that does exactly what I want.
> I'll need to iterate over the file several times, but that's not a
> problem!

I'm afraid you're about to do something the hard way, so forgive me if
I misunderstood you. Here is what you probably should do (and what I
meant earlier):

========

#!/usr/local/bin/lua

local subs = {
a = "α",
b = "β"
---...
}

local function mysubs(lines)
  for i,v in pairs(subs) do
    lines = string.gsub(lines, i, v);
  end;
  return lines;
end;

file = io.stdin:read("*all");

file = string.gsub(file, "localgreek(%b{})", function(lines)
     return "localgreek"..mysubs(lines);
   end);

io.stdout:write(file);

=======

HTH,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant