Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.


Post Reply  Post Thread 

Storing and Running Perl Programs

Post Bank
Posting Manager
******

Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.

Signin to Remove this Post

bomber
Junior Member
*


Posts: 34
Group: Registered
Joined: Sep 2006
Status: Offline
Reputation: 0
Points: 250 (Donate)
Post: #1

Smile Storing and Running Perl Programs


Homework: Hello


To test your ability to store and run a Perl program, enter and execute something like this classic code:

#!/usr/local/bin/perl -w
if ($#ARGV >= 0) { $who = join(' ', @ARGV); }
else { $who = 'World'; }
print "Hello, $who!\n";

Here's How:

Let us assume that the above lines are stored in a Unix file ~/bin/hello. (That's in your home directory, subdirectory bin, file hello.) You can then run the program by entering a command like:

perl ~/bin/hello
perl ~/bin/hello Citizens of Earth
perl hello (If you're in the ~/bin directory.)

If you expect to use this program a lot and want to execute it as a command, then you need to do five things.

1. The first line of the program should after a "#!" specify the location of the perl command, typically as #!/usr/local/bin/perl or #!/usr/bin/perl , as illustrated in the preceding example program. This line can also give command options, like -w (warn of possible inconsistencies).

2. Set the execute permissions of the program file. To make the file executable (and readable and writable) by only yourself, use a Unix command like:

chmod 700 ~/bin/hello

To make it executable and readable by all enter a Unix command like the following:

chmod a+rx ~/bin/hello

You may also need to use chmod a+x on the directories ~ and ~/bin. See "man chmod" for details and the security implications. (The MU program "chweb" can make a file accessible to the Web server and yourself, but not to other users. See "man chweb" for details.)

3. Edit your file ~/.cshrc or ~/.login to make directory ~/bin part of the path Unix searches for executables, with a line like this:

set path = ($path ~/bin)

4. This takes effect the next time you start a default tcsh or csh shell (.cshrc file) or login (.login file). If you want it to take effect immediately, enter the above set path command at the Unix prompt or enter execute your .cshrc or .login file with the "source" command. If you are using sh, bash, ksh or some other shell, alter ~/.profile or some other file to set the path at login.

If a program you want to execute has just been newly created, then issue the csh/tcsh command "rehash" to rescan the path.

If you perform (1)-(5), then you can execute your program via a command like this:

hello

19-09-2006 12:13 AM
Find all posts by this user Quote this message in a reply
Post Reply  Post Thread 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Simplest Perl CGI geekyone 1 221 15-04-2008 04:31 PM
Last Post: ivenms
  MySQL with Perl maddog39 4 618 09-08-2007 07:04 AM
Last Post: walsh
Smile Testing Perl Programs bomber 0 613 19-09-2006 12:39 AM
Last Post: bomber
Smile Taste of Perl bomber 0 653 19-09-2006 12:11 AM
Last Post: bomber
Smile State of Perl bomber 0 673 19-09-2006 12:09 AM
Last Post: bomber
Smile What Is Perl? bomber 0 632 19-09-2006 12:07 AM
Last Post: bomber

View a Printable Version
Send this Thread to a Friend
Subscribe to this Thread | Add Thread to Favorites
Rate This Thread:

Forum Jump:

Sign In to Remove Ads

Download 1000's of web templates. Unlimited access!
World's Best Web Hosting
Website of the Month

Create-a-Page for Free
SOTM June 2008


Accepting Submissions
for July 2008
Resources

Recommended Sites:



Visit our Sponsors!

Current time: 29-08-2008, 04:21 AM


Copyright © 2002-2008 MyBB Group
Powered By MyBB