in reply to sed in perl: syntax error at script.pl line 19, near “;$'”

All that you can realistically do here is to fiddle-with sed ... but you probably could have the job done right now already with a text editor.   Just sayin’.   The trouble is that sed is not a true parser, and such a thing is probably what you do need here.   It has no language awareness.   Therefore the slightest discrepancy between what your “one-liner” calls for and what the source-code contains ... anywhere ... is going to cause problems.   Long before this point, if I may be quite frank, I would have cut my losses and found a different way to do it.   “There’s More Than One Way To Do It™” very often means that the approach that you have first come up with isn’t the right way ... or even a way that will work at all.

In this case, you have to put your thinking-cap back on.   You seem to have wasted many days trying to do something in a few seconds when it would have taken minutes to do it by hand.   The “shell-script one-liner,” in all its various forms, is not only highly-overrated but virtually unmaintainable over time.   If what you truly need is to generate customized “Perl code,” well, that is simply a special-case of ... templating.   Which we already know how to do very well.   Template ... the same tool that generates so many of the world’s web pages now ... can quickly generate whatever you might need for it to do.

Replies are listed 'Best First'.
Re^2: sed in perl: syntax error at script.pl line 19, near “;$'”
by Laurent_R (Canon) on May 10, 2014 at 22:26 UTC
    The “shell-script one-liner,” in all its various forms, is not only highly-overrated but virtually unmaintainable over time.

    I disagree with this, although I broadly agree with the rest of what you said. I am using very commonly "one-liners", Perl or sed or awk or grep or cut or other (mostly Perl), to pre-process big files and get the right input format for my real programs. One-liners can be a bless of God.