Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Programming Language to generate Perl Scripts

by samaadhi (Initiate)
on May 14, 2010 at 15:21 UTC ( [id://840016]=perlquestion: print w/replies, xml ) Need Help??

samaadhi has asked for the wisdom of the Perl Monks concerning the following question:

Hey, I am working on an academic project, and I need to generate loads of Perl scripts, basically to automate a function. Which is the best programming language to achieve this? Regards,

Replies are listed 'Best First'.
Re: Programming Language to generate Perl Scripts
by jettero (Monsignor) on May 14, 2010 at 15:28 UTC
    perl

    -Paul

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?.

      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.

        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

        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.

        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!

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).

    Cheers Rolf

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.
Re: Programming Language to generate Perl Scripts
by Anonymous Monk on May 14, 2010 at 21:32 UTC
      I do not see any connection to Treex::PML, though.
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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://840016]
Approved by jettero
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2024-03-19 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found