[DCPM] To quote or not to quote.

Neil Williams linux at codehelp.co.uk
Thu Jun 30 13:22:35 PDT 2005


I'm using Perl to parse some XML and generate C source code, including the 
Makefile.am, configure.in, autogen.sh, *.c, *.h and ChangeLog.

http://qof-gen.sourceforge.net/
(currently only PHP on the public site, Perl code is in CVS)

The code used as a template is also a live project:
http://pilot-qof.sourceforge.net/

Naturally, I want to keep the code in the templates in sync with the code in 
the real project. However, I do NOT want to have to include placeholders in 
the REAL project. The places where the template uses modified strings are not 
predictable in a manner that would suit a regexp.

Whilst some files are 100% generated, there are only small changes required to 
certain files - the name of the final program, copyright notices, names of 
the objects being used in the template - so I've got some files that are 10k 
of unchanged text with only maybe a dozen lines changing. 

I want to be able to update these sections with changes in the main project as 
easily as possible and that means I'd like to be able to simply cut and paste 
without worrying about enclosed quotation marks (single or double) or 
back/forward slashes. Currently, I have to watch the editor syntax 
highlighting carefully and manually escape any rogue characters.

I can't use print <<EOF; because the content needs to be stored in a variable 
and is not printed immediately.

Is it safe to use qq//; over multiple lines (using q$ $;maybe)?

Or should I save the unchanging code to snippet files that are opened by the 
script? I was hoping to avoid that in the hope that I could package a single 
script file instead of lots. If I'm going to use external snippet files, I'd 
need a way to use the same files in PHP too. (The PHP scripts receive input 
from HTML forms, cache the results in a MySQL table and then generate the 
final code. The perl parses the XML and generates the code from that, caching 
in RAM.)

sample lines:
/** \brief documentation here
*/
	struct poptOption options[] = {
		{ NULL, '\0', POPT_ARG_INCLUDE_TABLE, poptHelpOptions, 0, "Help options:", 
NULL },

I want to retain line breaks and tabs.

Also:

1. How does a perl script accept command-line arguments? (your-name, email, 
prefix, output-dir etc.)

2. once this is done, what's the easiest way to execute the ./autogen.sh with 
parameters to start the build from within the perl script that generated the 
code? Can the one command include the make?
(no need for make install as these are example / test programs).

-- 

Neil Williams
=============
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://mail.pm.org/pipermail/devoncornwall-pm/attachments/20050630/fcd42390/attachment.bin


More information about the Devoncornwall-pm mailing list