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

I think this is truly a newbie question, but I am forced to ask, since could not find what I need neither here or in the internet (searching for command line, perl and such).
Please can someone tell me if it is possible to give perl a "program, line by line" from the command line with activeperl? I run perl on a win2k PC.

I know one can go into perl shell, type the lines and go CTRL+Z, but I'd like something like:
c:\>perl '#!usr/bin/perl print "\nhello, world!";'
NOTE: if you are new to perl inline compile, typing perl into the command line (when perl exe is in your system path) executes the shell, from where you can type perl code and execute it after you press CTRL+Z followed by return
EXAMPLE
C:\>perl print "\nHello world. Hope it's not rainy today!"; ^Z Hello world. Hope it's not rainy today!
Am I asking something possible, or I am simply in delirium?
I hope I have been clear in my request.
Thanks everybody.

Replies are listed 'Best First'.
Re: Command line perl 'compile'
by japhy (Canon) on Jul 08, 2002 at 16:05 UTC
    Remove the shebang line! And check the perlrun docs. You want something like: perl -e "print qq{Hello world.\n}" Notice that Windows requires double-quotes.

    _____________________________________________________
    Jeff[japhy]Pinyan: Perl, regex, and perl hacker, who'd like a job (NYC-area)
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      This works perfectly.
      The shebang is there because my purpose is to feed the perl interpreter a program contained in a file and parsed by another program!
      There is no real use for what I need, but I thought it could be good practice.
      I now understant that the comment from the shebang invalidates all the codeline and hence must be eliminated from the programs read.
      Many thanks, especially for the quick answer.
Re: Command line perl 'compile'
by flounder99 (Friar) on Jul 08, 2002 at 17:20 UTC
    Another method is to pipe to the executable. This can be dangerous but it is possible. I would not do this with anything complicated or containing metacharacters. But simple programs can be piped.
    C:\>echo print "hello world!"|perl hello world!

    --

    flounder