[Courses] [Perl] Part 1: Getting Started

Devdas Bhagat devdas at dvb.homelinux.org
Tue Apr 5 09:13:29 EST 2005


On 04/04/05 17:18 -0500, Fazia Begum Rizvi wrote:
> 
> Hi Dan,
> 
> I've just joined the Linuxchix Courses list, specifically for your class 
> on Perl. I'll be following it every week.
> 
> Since I joined a bit late, I went to the archive and read the first two 
> messages. I've already done my first program. :-)
> 
> I also have my first question. Though I'll be doing later programs on a 
> linux server, I put together this first one on my Mac (OSX). Everything 
> worked except I could not get the program to run by simply typing 
> "hello.pl" after insterting the shebang line. (It runs just fine if I type 
> "perl hello.pl".
> 
On Unix systems, the OS needs to be told that the file is an executable.
You can do this by running chmod +x file. Refer to the chmod manual for
more detail on the options it takes. man 1 chmod.

Also, on most Unix systems, the current directory is not in your PATH
environment variable. The PATH is the list of directories where an
executable is looked for by the shell. To see your current PATH, 
echo $PATH in your shell. If you had marked that file as executable,
then you should try running ./hello.pl to see if it works.

> I know that some flavors of perl can be different. Is this the case here? 
> Or did I perhaps write something incorrectly?
> 
When you call the script as perl <scriptname>, the shell executes the
perl binary, which proceeds to run through the commands in <scriptname>.

When you use the shebang line, the shell invokes the interpreter
referred to by the command on the shebang line, and then that handles
the rest of the script.

> #!/usr/bin/perl -w
> use strict;
> # My very first perl program April 4, 2005 - Fazia
> my $who;                        # Declare variable
> $who = "world";                 # Assign variable
> print "Hello, world!\n";        # Print result
> 
Did you mean to use $who up there?
print "Hello, $who!\n";

Devdas Bhagat


More information about the Courses mailing list