Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Command line perl 'compile'

by CodeHound (Beadle)
on Jul 08, 2002 at 15:59 UTC ( [id://180207]=perlquestion: print w/replies, xml ) Need Help??

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-23 07:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found