Re: Programming Language to generate Perl Scripts
by jettero (Monsignor) on May 14, 2010 at 15:28 UTC
|
| [reply] [Watch: Dir/Any] |
Re: Programming Language to generate Perl Scripts
by marto (Cardinal) on May 14, 2010 at 15:30 UTC
|
Welcome to the Monastery. Based on the information given the obvious answer is Perl, however perhaps your approach isn't right, could explain exactly what you want to do/automate? See How do I post a question effectively?.
| [reply] [Watch: Dir/Any] |
|
Hey, sorry about that.
Basically, I have an XML file. I need to parse this file, get the attributes and elements and use them to generate multiple perl scripts.
My question is, what programming language would be the best to do this? It doesn't seem right to use perl to generate perl scripts as it will become very messy.
| [reply] [Watch: Dir/Any] |
|
Use Perl and the module XML::Twig to parse your XML file. Do you actually need to generate separate perl scripts or simply perform a fuction based on values within your XML file?
"It doesn't seem right to use perl to generate perl scripts as it will become very messy."
What makes you think this would be any easier in another language?
Update: fixed typo
| [reply] [Watch: Dir/Any] |
|
|
|
|
|
Perl has multi-line strings, customisable string delimiters (e.g. qq!!) and even nestable string delimiters (e.g. qq{}), making it a great language to use to generate code. It also has strong templating and XML parsing tools. It would truly be an excellent choice.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
What makes you think it would not be messier in any other language? Perl is good at this sort of data munging, and has stuff like eval built right in!
| [reply] [Watch: Dir/Any] [d/l] |
Re: Programming Language to generate Perl Scripts
by LanX (Saint) on May 14, 2010 at 17:04 UTC
|
Frankly I doubt that generating "loads of Perl-scripts" is the best solution to your problem.
Most probably you only need to generate "loads of Config-files" read by one Perl script.
And maybe you can just leave the data within the XML and use it right away as config file...
Anyway a templating syntax for Perl can be very easily achived with a regular expression and multiline strings. You should only take care about having no conflicts with perlsyntax ... e.g. § has no meaning in Perl and uppercase letters are reserved.
$tmpl=<<'_tmpl_end';
§CMD§ "§PARA§";
_tmpl_end
%value=(
PARA => 'blabla',
CMD => "print"
);
$tmpl=~s/§([A-Z]+)§/$value{$1}/g;
print $tmpl;
generates
print "blabla";
Please note there is more than one way to achieve this in Perl...and you can easily add syntax checks for your template (catching undefined variables and/or typos).
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: Programming Language to generate Perl Scripts
by Marshall (Canon) on May 16, 2010 at 23:11 UTC
|
You want to automate a function. Show some examples. | [reply] [Watch: Dir/Any] |
Re: Programming Language to generate Perl Scripts
by Anonymous Monk on May 14, 2010 at 21:32 UTC
|
| [reply] [Watch: Dir/Any] |
|
I do not see any connection to Treex::PML, though.
| [reply] [Watch: Dir/Any] |
Re: Programming Language to generate Perl Scripts
by Anonymous Monk on May 14, 2010 at 23:06 UTC
|
I think your question reveals that your academic project will be a complete failure. If you don't have any idea what you're doing I suggest you find something else. | [reply] [Watch: Dir/Any] |