Perl/Code: Difference between revisions

From Citizendium
Jump to navigation Jump to search
imported>John Stephenson
(categories)
imported>Chris Day
No edit summary
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{subpages}}
In a Linux/Unix environment it has become standard practise to include a special comment in a script's first line, which will direct the command interpreter (shell) where to find the executable, the so-called "hash bang" line. Usually the complete path to the executable is written, thus making this line in the script dependent on the host's file system structure.
In a Linux/Unix environment it has become standard practise to include a special comment in a script's first line, which will direct the command interpreter (shell) where to find the executable, the so-called "hash bang" line. Usually the complete path to the executable is written, thus making this line in the script dependent on the host's file system structure.
Example:
Example:
Line 19: Line 20:


This however requires that a valid Perl executable exists in <code>/usr/bin/</code> or the shell will produce an error. The '-w' option is always recommended, it will direct Perl to produce warnings about unsafe code such as using undeclared variables, and other potential traps.
This however requires that a valid Perl executable exists in <code>/usr/bin/</code> or the shell will produce an error. The '-w' option is always recommended, it will direct Perl to produce warnings about unsafe code such as using undeclared variables, and other potential traps.
[[Category: Computers Workgroup]]
[[Category: CZ Live]]

Latest revision as of 13:09, 24 March 2008

This article is developing and not approved.
Main Article
Discussion
Related Articles  [?]
Bibliography  [?]
External Links  [?]
Citable Version  [?]
Code [?]
Addendum [?]
 
A collection of code samples relating to the topic of Perl.

In a Linux/Unix environment it has become standard practise to include a special comment in a script's first line, which will direct the command interpreter (shell) where to find the executable, the so-called "hash bang" line. Usually the complete path to the executable is written, thus making this line in the script dependent on the host's file system structure. Example:

#!/usr/bin/perl -w

# script 'tst'

print "Hello, world!\n";

Now, instead of running

$ perl tst

you can run just the script itself:

$ ./tst

which will produce the expected

Hello, world!

This however requires that a valid Perl executable exists in /usr/bin/ or the shell will produce an error. The '-w' option is always recommended, it will direct Perl to produce warnings about unsafe code such as using undeclared variables, and other potential traps.