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

Is there a program or module which can prepare perl code to be run from the command line, using the -e method? I am doing this because I want to embed the perl code in a shell script, which will render html output using w3m. I know I could just put the perl code into it's own file, but I thought I'd ask.

Replies are listed 'Best First'.
Re: Automatically prepare code for perl -e
by mscharrer (Hermit) on Apr 30, 2008 at 19:00 UTC
    Perl can read the program from STDIN, so you could do it like this:
    #!/bin/sh perl - <<'__END__' argument0 argument1 # Perl commands print 'Hello World', "\n"; __END__ # Other shell commands
Re: Automatically prepare code for perl -e
by pileofrogs (Priest) on Apr 30, 2008 at 19:59 UTC

    I might not understand the question, but the obvious answer (to me anyway) is to put code in shell variables Like so:

    #!/bin/sh MESSAGE='Hello World\n' perl -e "print \"$MESSAGE\""

    (I'm not sure if '\n' gets expanded by the shell, so this example might not exactly work, but it shows the principle.)

    Is that what you're asking for, or did I misunderstand the question?

    -Pileofrogs

Re: Automatically prepare code for perl -e
by Anonymous Monk on May 01, 2008 at 08:39 UTC
    You maybe write one using PPI