Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^2: Programming Language to generate Perl Scripts

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


in reply to Re: Programming Language to generate Perl Scripts
in thread Programming Language to generate Perl Scripts

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.
  • Comment on Re^2: Programming Language to generate Perl Scripts

Replies are listed 'Best First'.
Re^3: Programming Language to generate Perl Scripts
by marto (Cardinal) on May 14, 2010 at 15:43 UTC

    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

      I need to generate separate perl scripts, based on the values within the XML file. I am a n00b to perl. What do I need to do say if I want to write $samaadhi(not the value, the text) into a file.

      Wouldn't it be a mess of single quotes and double quotes? Still giving a thought of using perl. XML::Twig seems cool.

        Wouldn't it be a mess of single quotes and double quotes?
        Maybe. Why do you think it will be less of a mess of single quotes and double quotes if you would program it in a different language?

        # Perl print '$samaadhi'; # Prints the text, not the value. # shell echo '$samaadhi'; /* C */ #include <stdio.h> printf("$samaadhi"); // Java System.out.print("$samaadhi"); # Python print "$samaadhi"; { Pascal } Write("$smaadhi"); // C++ #include <iostream> std::cout << "$samaadhi"; -- Haskell putStrLn "$samaadhi"; # MMIX string BYTE "$samaadhi", 0 Main GETA $255,string TRAP 0,Fputs,StdOut
        Seems it's not any easier in another language.

        Wouldn't it be a mess of single quotes and double quotes?

        No. For the reasons I already gave, it would be less of a mess in Perl.

        Perl: print($fh q{for (keys(%h)) { print("$_: $h{$k}\n"); }}); C: fprintf(fh, "for (keys(%%h)) { print(\"$_: $h{$_}\\n\"); }"); fprintf(fh, "%s", "for (keys(%h)) { print(\"$_: $h{$_}\\n\"); }"); fputs("for (keys(%h)) { print(\"$_: $h{$_}\\n\"); }", fh);

        3 or 4 extra escapes in C.

Re^3: Programming Language to generate Perl Scripts
by ikegami (Patriarch) on May 14, 2010 at 15:46 UTC
    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.
Re^3: Programming Language to generate Perl Scripts
by Anonymous Monk on May 14, 2010 at 16:06 UTC

    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!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-04-19 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found