Programming on NetWare Made Easy with Perl Scripting
Articles and Tips: article
01 Nov 1999
Provides an overview of Perl and other scripting languages. Shows how NetWare interfaces with Perl and how developers can use Perl to create NDS-enabled applications.
Programming in its infancy used cryptic machine language, which eventually gave way to an improved assembly language and finally maturing to higher level system programming languages. The last two decades have seen a fundamental change in the way people write programs from the strongly typed system programming languages to the world of loosely typed scripting languages, like Perl. Reasons for this change include faster machines, better scripting languages, the increasing importance of graphical user interfaces and component architectures, and the growth of the Internet.
Scripting languages achieve a higher level of programming and more rapid application development than system programming languages. Perl, a popular scripting language initially designed as a glue language for the UNIX operating system, is now very popular with system programmers and Web developers alike. Perl on NetWare helps programmers create NDS-enabled applications very quickly.
Scripting languages represent the "present" of programming. System programming languages that came in as a substitute for the assembly programming languages represented the recent past.
In assembly language programming, the programmer had difficulty handling low-level details such as register allocation and procedure calling sequences. With the switch towards system programming languages, the programmer had a compiler that handled many of these tasks. In addition to taking care of many low-level tasks, compilers provided simple control structures. Consider this comparison: each line of code in system programming language translates to about five machine instructions, compared to one instruction per line of assembly language.
System programming languages are designed to handle tasks such as creating applications from scratch, easing the burden placed on assembly programmers. Scripting languages, by contrast, integrate different components normally written in system programming languages. Used together, system languages and scripting languages produce a programming environment of exceptional power. System languages create valuable components that can be assembled using scripting languages.
Reasons for the popularity of scripting languages included the following:
Increased emphasis on graphical user interfaces (GUIs). It is very easy to create a GUI using scripting languages like Tcl/Tk or Visual Basic.
The growth of the Internet. Perl has become the defacto language for CGI scripting, while Java script is very popular for scripting Web pages.
Improvements in scripting technology. Modern scripting languages are much more efficient than earlier versions.
Increased hardware speed. Scripting languages are generally interpreted, but with the advent of powerful hardware, execution speed has become a non-issue compared to the speed of software development.
Scripting languages are quite easy to learn compared to system programming languages they have simpler syntax and constructs.
What is Perl?
Perl is the acronym for Practical Extraction Report Language. It was originally authored by Larry Wall, who describes Perl this way:
"Perl is an interpreted language optimized for scanning arbitrary text files...It's also a good language for many system management tasks. The language is intended to be practical (easy to use, efficient, complete) rather than beautiful (tiny, elegant, minimal). It combines (in the author's opinion, anyway) some of the best features of C, sed, awk, and sh, so people familiar with those languages should have little difficulty with it...Expression syntax corresponds quite closely to C expression syntax...Perl can slurp in your whole file as a single string. Recursion is of unlimited depth. And the hash tables used by associative arrays grow as necessary to prevent degraded performance. Perl uses sophisticated pattern matching techniques to scan large amounts of data very quickly. Although optimized for scanning text, Perl can also deal with binary data, and can make dbm files look like associative arrays (where dbm is available)..." (Larry Wall, Tom Christiansen, and Randal L Schwartz, Programming Perl, O'Reilly " Associates, September 1996)
Perl was originally founded on the UNIX platform. Later on it was ported to many other popular platforms. The porting effort required in moving Perl scripts between two platform is very minimal. Perl finds its most devoted followers in areas of system administration and Web development. Perl is now being used in every field imaginable.
Perl is a simple language to learn. Types and structures are easy to use and understand. Perl borrows most of its syntax from C and other text processing facilities such as sed and awk. Perl can be extended easily in a modular fashion by calling modules written in languages such as C/C++. You can also embed Perl scripts in languages such as C and execute those scripts by making calls to internal APIs of the Perl interpreter.
Perl is not a strictly interpreted language. It has a compilation cycle and an interpretation cycle. During the compilation process the script is converted into intermediate code after checking for syntax and semantic errors. This intermediate code is generated only after doing various compiler optimization techniques. Once the intermediate code is generated, it is passed on to the interpreter for execution.
Perl provides only three built-in data types scalars, arrays, and associative arrays. Scalars are simple and can store a string value or a numeric value. Arrays store a list of scalar values, which can be indexed with integer values. The size of the array can be varied dynamically. Associative arrays are similar to normal arrays except that they are indexed by strings. An associative array is also known as a hash.
Like every other conventional language, Perl, provides user-defined functions. You can define a group of related functions in a file and use those functions by including the file in your script. The essential difference between Perl functions and functions in other languages lies in the passing of parameters. In Perl the parameters are passed as a list of scalar values both for the input type and return type. If there is no explicit return statement specified in the code, the result of the last expression evaluated is returned.
With Perl, you don't have to reinvent the wheel because Perl provides modules, groups of related functions similar to the library files we have in C/C++. These modules aid in modular programming. Programmers can write the modules in Perl. Normally they are a mixture of C/C++ and Perl. To meet specific requirements, the programmer can search the CPAN (Comprehensive Perl Archive Network), a repository where all Perl resources are found. If the required module is found, the programmer can install it by downloading it from CPAN and start working on it.
Some features of Perl prove handy for object-oriented programming, including classes, objects, methods, constructors, destructors, inheritance, and overloading.
Components of a Perl System
A running Perl system includes the following components, as shown in Figure 1.
Figure 1: A snapshot of a running Perl system.
Perl Object API. Represents the APIs that manipulate all internal data structures, such as variables, symbol tables, and stacks, as well as resources such as files and sockets.
Variables. Represent the name value pair.
Symbol Tables. Contain hash-value pairs. Key values are strings (representing the variable names) and hash values (pointers to the typeglob).
Stacks. Perl keeps runtime information on different stacks (unlike C, which keeps information about subroutine parameters, temporary parameters, and auto variables to a single stack). In Perl there are separate stacks for function arguments, temporary variables, local variables, and so forth.
I/O Abstractions. Perl internally uses an object called PerlIO for all I/O operations.
Translator. The translator converts Perl script into opcodes. Ececuter, which is part of the interpreter, executes these opcodes.
There are two ways to extend the Perl interpreter:
Extend Perl. You can add a C module that can do things for which Perl is not intended. This is the case when the program needs to get into the details of complicated data structures, or needs speed, type safety, and access to existing libraries. The ability of Perl to integrate well with C code is something seldom seen in scripting languages.
Embed Perl. Embedding Perl is opposite to extending it. Whenever there is a task you can execute in Perl because of its ease of use and simplicity, you can write a script for that and execute it from the C/C++ application that has been written. Making calls to the Perl internal API does the task.
Does Perl Run on NetWare?
Yes, Perl does run on NetWare. With the positioning of NetWare as the fastest Web Server platform, it was imperative to port Perl to NetWare. From NetWare 4.11 onwards, Perl has been supported on NetWare. The current version of Perl shipped with NetWare is Perl 5.003_07. It is based on the Active State Windows 32-bit version of Perl. The latest build of Perl on NetWare is freely downloadable from the DeveloperNet site at:
NetWare Interfaces to Perl
There are two interfaces to Perl on NetWare:
LCGI. Local Common Gateway Interface (LCGI) is used to return an HTML page to the client browser from a Perl script run from an HTTP server.
Text interface. In the text interface you can run a Perl script from the server console.
Writing Perl scripts on NetWare is as easy as on any other platform. Popular scripts in other platforms can easily be ported to NetWare with minimal effort. With Perl on NetWare, developers and network administrators can take advantage of NDS to quickly and easily create directory-enabled applications and utilities. With the help of UCSExt, developers can quickly create applications that leverage Novell's range of network services and Intranet infrastructure. Perl also helps developers and administrators manage and automate script execution across intranets and the Internet.
Perl Modules for NetWare
Perl owes much of its success to the wide availability of third-party modules (CPAN discussed earlier). The strength of a language lies more in the availability of libraries than in pure language features. Of the innumerable third-party modules, a few of them are worth mentioning because of their popularity. These modules are already ported to NetWare and are being shipped with the latest Perl interpreter.
CGI. The very purpose of Perl being ported to NetWare is to aid CGI programmers. The CGI module allows programmers to use Common Gateway Interface scripting, which is the most common way for users to interact with a Web server. This module comes first in popularity, as shown by the download statistics in CPAN.
SDBM_File. This is the DBM library that's ported along with Perl to NetWare. It gives Perl programmers a simple, easy-to-use database. The database is stored in a file on a local disk. These are hashes on disk. Every element in the file is accessed using a hash key.
DBI. Perl DBI is the database access API for Perl. The DBI defines a set of functions, variables, and conventions that provide a consistent database interface independently of the actual database being used. DBI is simply an interface, while the drivers do the real work.
DBDODBC. This module implements the database driver for ODBC on NetWare. This module contains the implementation of the DBI methods written using the private interface functions of the ODBC engine. ODBC Manager for NetWare is the product to be used with DBDODBC on NetWare.
UCSExt. This is the module from which you can use Novell's Universal Component System (UCS). UCS allows the programmer to develop applications that use software components on any network machine. UCS has its strength in its reusability. UCS components can be accessed from Perl as well as from other Novell scripting solutions. With UCSExt, you can call reusable components such as UCX components, JavaBeans, and even remote OLE components on a Win32system. This module acts as the interface for writing NDS-enabled applications. More information on the UCS components can be found at http://support.novell.com/techcenter/articles/dnd19990401.html.
Note: Perl shows its particular strength on the Open Source code. It is governed by the GNU licensing terms. Perl is freely available. You can download the source code from the CPAN sites, such as http://www.perl.com/cpan, and rebuild the entire interpreter.
The compromise of scripting is that programmers give up execution speed and strength of typing for higher programming productivity and software reuse. When hardware prices are going down and software development prices are going up, this compromise makes sense. The next century will demand more and more gluing tasks, ensuring a good future for scripting.
The range of scripting languages includes Java Script, NSN, Python, Tcl/Tk (in UNIX and Windows), and Visual Basic. Each language has its own strengths and weaknesses. Programmers use Perl because of its practical capabilities, its excellent text support, and its highly idiomatic, compact code.
Hopefully, this article shows that
scripting is valuable.
extensive gluing of components can result in higher productivity.
Perl can be effectively used for NDS-enabled applications.
Note: See the following for more information:
J.Ousterhout, Scripting: Higher Level Programming for the 21st Century, http://www.scriptics.com/people/john.ousterhout/scripting.html
Larry Wall, Tom Christiansen, and Randal L Schwartz, Programming Perl, O'Reilly & Associates, September 1996
Sriram Srinivasan, Advanced Perl Programming, O'Reilly & Associates, August 1997
Joseph N. Hall and Randal L Schwartz, Effective perl Programming, Addidson-Wesley, 1998
Novell Inc, Perl 5 for NetWare Documentation, http://developer.novell.com/cgi-bin/download/perl5_doc.exe
* Originally published in Novell AppNotes
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.