Using Perl

Perl is high-level programming language that derives from C, scripting languages such as awk, and shell secripting. Although Perl compilers are available, Perl usually is compiled on the fly at run time. Perl is highly protable. Perl code can be run without major changes on almost every operating system.

Perl is good at handling processes, files, and text. It is commonly used to process the common gateway interface (CGI) results of user input to Web forms. Because of its popularity on the Web, Perl is a very good language to get to know.

In addition, Perl is often used for automating administrative functions because it has access to the shell.

Perl variables are not types, but the language does have several different kinds of variables:

  • Scalar variables are numbers or strings, depending on the context.

  • Arrays can be accessed by index.

  • Associative arrays can be accessed by key.

For more information on Perl, check out Perl and CGI: Visual QuickStart Guide, published by Peachpit Press. And visit

http://www.perl.com

the Web site for the Perl community.

To display the user's ID number using Perl:

1.
In a tex file, type

#!/usr/bin/perl
print "Hello, your user ID -
Is $< 
";
Print "Have a nice day! 
";

2.
Save the file as testperl (Figure 12.23).

3.
At the command prompt, make the file executable:

chmod +x testperl

4.
Run the file by typing

testperl

Your numerical user ID will be shown (0 is the numerical ID for root, shown in Figure 12.24).

Tip

A large collection of built-in variables are available in Perl, including $< (the user ID) and $$ (the process ID).


Figure 12.23. Entering #!/usr/bin/perl tells the shell to use Perl to process the code file.


Figure 12.24. Perl includes many built-in variables, such as $<, which stores the user's ID number.


Python and Tcl

Many other development languages, systems, and libraries are included with Red Hat Linux 6.

Two of the more interesting are Python and Tcl.

Python is an object-oriented language that can be run interactively or by interpreting code module files. Python is in the public domain. It was created by Guido van Rossum and named after the Monty Python performers. Features in Python include modules, classes, exception and dynamic data typing. You can write programs in Python that can be displayed in X11: for example, on the Gnome desktop. You'll find the Python documentation at /usr/docs/ python – docs –1.5.1.

Tcl—short for tool control language—is a simple scripting language designed to be embedded in other languages. In other words, Tcl, originally created by John Osterhout, is intended to be the glue that combines more powerful languages and libraries. Tk is the companion widget set that allows Tcl to be used in a windowing fashion. You will find full Tcl documentation at http://www.scriptics.com


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.37.126