#!/usr/bin/perl -w print ("5 beer, please.\n"); exit;
$ chmod +x hw.pl $ ls -l -rwxr-xr-x 1 ntakebay ntakebay 45 Apr 9 20:00 hw.plRemember the unix permissions? To run a script, the file has to be executable (x). When you compile a C program, gcc automatically make the object code executable. But we have to manually change the permission mode by chmod command for perl script. If you use minus sign (chmod -x hw.pl), the executable bit get unset.
chmod u+w file | user who owns it can write |
chmod o+r file | other people can read |
chmod ugo-wx file | user, group, and others cannot write or execute |
chmod -wx file | same as above |
#!
tells that the script should be
``interpreted'' by a ``perl interpreter'' program /usr/bin/perl.
The perl interpreter program perl is usually installed at this
location in linux and mac OS-X. But in other unix system, you may
find it to be installed in /usr/local/bin/perl. Then the
first line should be ``#
!/usr/local/bin/perl''.
To find the location of the perl interpreter, try
which perl
print "5 beer, please.\n";
You'll notice that things are more relaxed (flexible) in perl than in C in general.