Solved

compile and run a perl program

Posted on 2003-10-22
5
863 Views
Last Modified: 2009-12-16
how to compile and run a perl program that outputs the hello world to the unix screen.
0
Comment
Question by:mordi
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:ultimatemike
ID: 9598525
Do you mean compile as in "Compile into an .exe file" or compile as "execute the script"?


Also, details about what type of system your using will be helpful.
0
 
LVL 2

Expert Comment

by:ultimatemike
ID: 9598547
I'm blind.  You put Unix. :(



Try using pp - I haven't used it myself, but it is supposed to be able to create executable Perl files for distribution.


http://search.cpan.org/~autrijus/PAR-0.75/script/pp
0
 
LVL 8

Expert Comment

by:inq123
ID: 9598607
Hi mordi,

Do you mean a simple hello world script to echo on console screen on Unix?  First you need to install perl, which you can download from http://www.perl.com/pub/a/language/info/software.html, then you just need to test first script this way:

perl -e 'print "hello, world\n"'

The script is enclosed in the single quotes, if you want the script to standalone name this code test.pl:

#!/usr/bin/perl

print "hello, world\n";

Then launch the script by typing "perl test.pl" or "./test.pl" if you chmod-ed to 0755 for example.

That's it.  You don't really need to compile a perl program because perl interpreter will do it on-the-fly for you.

Cheers!
0
 
LVL 3

Author Comment

by:mordi
ID: 9598733
could an output of a ls command be printed in the screen from a perl program?
0
 
LVL 8

Accepted Solution

by:
inq123 earned 91 total points
ID: 9598820
use this code:

open(IN, "ls |"); # open a pipe to read ls command's output
while(<IN>) # read pipe line by line into $_ ($_ is special so you don't need $_ = <IN> syntax
{
  print; # print line by line (it's printing the default $_ variable, which is storing the line)
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now