|
Home | Switchboard | Unix Administration | Red Hat | TCP/IP Networks | Neoliberalism | Toxic Managers |
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and bastardization of classic Unix |
Search engines:
Official sites:
Reference: see below
Bookshelf
Top community sites:
Products, projects and resources:
People:
Press:
See also Perl FAQ Index .Beginning with Perl version 5.004, the Perl distribution itself includes the Perl FAQ.
See also Softpanorama Hall of Fame -- Larry Wall
Web Review - Perl -- Short history of Perl
The June 2001 issue of Fast Company Magazine, page 156, features Perl as being one of the "best-of-the-best innovations
What: The Perl programming language
When: December 18, 1987
Where: Santa Monica, California
Who: Larry Wall, former employee of Unisys Corp., currently affiliated
with O'Reilly & Associates Inc.
The Internet economy has its share of stars, from John Chambers to Steve Case. The Perl programming language also deserves a place in the pantheon of Web heroes. Known as the "duct tape of the Internet," Perl has been hailed as the single most important tool for expanding Web sites quickly and for minimizing development times. More than half of the sites on the Web are built using Perl as the foundation, or "glue," that holds together text files and other applications.
How Perl was created, and how it works, is as important as what it does. Perl is a poster child for the open-source software revolution -- volunteer programmers from all over the world work to make it better. And unlike most computer languages, which are based on a strict logic and prescribe a single "right" way to code for an outcome, Perl was created by linguist Larry Wall to mimic natural languages. "There are many ways to say the same thing, depending on what you're optimizing for -- elegance, speed, simplicity," says Wall. This allows Perl programmers a large measure of creative expression in the way that they build sites -- a quality not often found in computer coding.
Like any major computer innovation, Perl has its share of quirks and eccentricities. For example, the most popular physical symbol of this software triumph is . . . the camel. Years ago, O'Reilly & Associates put a camel on the cover of Programming Perl, the bible of Perl developers everywhere. The camel has become so popular that the O'Reilly Web site devotes a section to the ways in which the finer points of trademark law apply to the Perl camel.
It's one of the many indications of the
cultlike following that has sprung up around the language. Wall encourages the
culture, in whatever strange forms it may take. "With my linguistics
background, I've learned that a language without a culture is a dead
language," he says. "Encouraging programmers to feel creative in their coding
process means that there is a real base of mind power there when we go out and
ask them to help us solve technical problems with Perl."
--Alison Overholt
An Overview of Perl -- from Programming Perl, 2nd Edition
Evolutionary Changes in Freeware -- An edited excerpt from Larry Wall's Keynote Address at 1997 Perl Conference. Web Review, Apr. 10, 1998
Web Review -- Interview with Larry Wall and Tom Christiansen
Perl versus .... - some comparative language discussions. Includes Perl versus tcl, python, java, and others.
Several books are available online: see Perlbooks. Please consult PERL Reference for a more complete list of tutorials. It does not make sense to try to learn Perl from WEB tutorials or, God forbid, from the Perl manual. Perl books. including books from www.mcp.com are much more appropriate (but please avoid popular Learning Perl and Learning Perl on Win32 twins :-).
Actually there are few good online tutorials on Perl.
Practical Perl Programming by A. D. Marshall 1999
Picking Up Perl, a Freely Redistributable Perl Tutorial Book. a small tutorial currently it is in version 0.11.
Perl by Example -- online book by David Medinets More like a reference then tutorial. Still it's one of the few published books available online.
Please note that all O'Reilly Perl books have one chapter online. Those chapters are a nice complement to full online books.
**** http://www.oreilly.com/catalog/perlsysadm/chapter/ch09.html Chapter 9 of "Perl for System Administration" online. Chapter 9 is an in-depth look at one of the more common system administrator's duties: sifting through log files.
The chapter covers everything from basic syslog, text only log files to Microsoft NT, binary log files and how to interpret them using Perl. David N. Blank-Edelman does more than just explain how to grok the files, he addresses several other problems, such as log file rotation and stateful vs stateless data. There is also a very detailed section on log file analysis. He covers several different algorithms for analyzing the logs and turning them into useful data. Also, he addresses the use of databases in the logfile analysis process.
Reviews
As for WEB tutorial IMHO only explanation of a particular language features can probably be useful.
Regular expressions (see special section devoted to this important feature below)
References
General
See also modules, regular expressions
VIM has (limited) support of Perl. See Softpanorama VI Editor Links
***** DzSoft Perl Editor 3.1 Very decent shareware editor with elements of Integrated environment. Contains built-in beautifier ! by Sergey Dzyubenko, Alexander Dzyubenko, DzSoft Ltd.
Perl Scripting Tool PRO Perl Made Easy Win32 editor.
NOTE: This is beta software. If you are not entirely comfortable using beta software, DO NOT install this version on your PC. We strongly recommend that BEFORE you install this software, you make a backup copy of your existing PST folder and put that copy in a separate area. Do not be alarmed if there is a big jump in beta build numbers; gaps exists because we create frequent internal builds. This is one of a series of beta releases of Perl Scripting Tool 2.00. As with any beta software, some features may not be fully implemented. If you find any problems with this software, please send us a bug report to: [email protected] .
ped A text editor with an emacs/vi-like user interface written in perl.[July 17, 1999]
Jul 08th 1999, 21:24 stable: none - devel: 0.1.2 license: Artistic
Perl::Tk
ptkpad.0.6.5.tar.gz
This is an implementation of my Tk NotePad only it is done in Perl::Tk. The implementation is progressing quite fast and most of the features have been implemented. Currently the only features that have not been implemented are some keystroke bindings.
Unfortunately there are a few bugs and is considered a beta release now, so please do not complain about bugs> I will welcome bug fixes. It originaly started out as a line by line conversion, but as I learn more about perl I am starting to optimize as well but this is a low priority.
Some features that have been added in addition to what is in my original TkNotePad are the New Window Menu item, as well as a line and column indicator to tell the position of the cursor, and a goto line. I have also added an Options menu for changing a few things like the fonts. Many more features are planned. screenshot
EDITOR | COST | REVIEWS From PBML Posters |
Perl Code Editor
from PerlVision |
Free | After Wordpad, this was my first Perl
editor. Syntax highlighting and line numbering is definitely a step
up. Favorite feature: line numbering. Submitted by: Bompa [read more reviews] |
Open Perl IDE by Jürgen Güntherodt |
Free | A big step up, yet still light on your cpu. This
is the one I use now because it's free and runs nicely even on my 122Mhz
laptop. Favorite feature: A "run" button that runs the script and shows errors in a box at the bottom of the screen, this saves a bunch of testing time. Submitted by: Bompa |
UltraEdit IDM Computer Solutions, Inc |
$35 | Full featured, tons of options, settings, and features.
Favorite feature: being able to "'comment out" whatever code I highlight with just one click, (and the reverse), great for troubleshooting. I loved it and might still cough up the 35 bucks. Submitted by: Bompa |
OptiPerl Xarka Software |
$59 | Full featured, tons of options, settings, and features,
but more money than I want to spend at this time. Submitted by: Bompa |
Perl Builder 2.0 from Solutionsoft |
$149 | Submit a review. |
visiPerl+ from Softpile |
$59 | Submit a review. |
Komodo from ActiveState |
$295 | Submit a review. |
DzSoft Perl Editor by DzSoft |
$59 | Like OptiPerl, full featured, tons of options, settings,
and features, but more money than I want to spend at this time. Submitted by: Bompa |
EditPlus by ES Computing |
$30 | Submit a review. |
SciTE Free source project. Project Admin:Neil Hodgson |
Free | Syntax highlighting for many languages, output pane,
C-like macros (via FilerX), quick, small and mighty :-) Submitted by: Jenda |
VIM Bram Moolenaar |
Free | Vi and emacs, the great unix editor debate. Personally I
like vim, it's quick, works great over slow links and has more features than
you can shake a stick at. Once you've grokked enough of the commands to make
this little baby run you'll never want to go back. mouse? mouse? i don't
want no steeenking mouse. You windows types can even join in the fun too.
Submitted by: Daniel Gardner |
[Oct. 07, 2000] A special module IPC-Run by Barrie Slaymaker([email protected]). After a user's spun up on bash/ksh, it provides useful piping constructs, subprocesses, and either expect-like or event loop oriented I/O capabilities.
www.perl.com Perl Reference/Networking
[Feb 20, 2000] pftp pFtp is a ftp client written in perl. It uses the Perl/Tk and Libnet libraries, both available from the CPAN FTP site. Download: pFtp 0.05
[Jan 28, 2000] DDJ EXAMINING PERLDAP by Troy Neeriemer
Netscape's PerLDAP is an important tool for both programmers and administrators because it provides a mechanism for accessing directory information from Perl. Troy presents a high-level overview of PerLDAP, along with details of how you can use it. Additional resources include perldap.txt (listings) and perldap.zip (source code).
Paw
(Perl ASCII Widgets) is a widgetset for generating a GUI on ASCII based
terminals. It contains button, radiobutton, label, line, listbox, text_entry,
pull-down-menu, filedialog, popup-box and more. Examples are included. This
software requires Perl::Curses.
[Apr 18, 2001] Drall -- Stable version 1.4.0.0. Much better that it was and now supports authentication using the same author's Averist module. Written in Perl (GNU license) Screenshots:
Here is the quote from the author page:
If you like Drall, please express your satisfaction with a donation: send me what you feel Drall has been worth to you. If you are glad that I developed Drall and distribute it as free software, rather than following the obstructive and antisocial practices typical of software developers, reward me. If you would like me to develop more free software, contribute.
1.5.0.0 (equal to 1.3.5.4, supports Averist 1.1.0.1 or later) - 22 February 2001 - new development tree
1.3.5.4 (supports Averist 1.1.0.1 or later) - 14 February 2001 - release candidate 3
Fixed output of TARGET attribute so that Drall can be run inside a frame even when Drall's dual-frame interface is disabled.
1.3.5.3 (supports Averist 1.1.0.1 or later) - 21 January 2001 - release candidate 2
Cosmetic code clean up.
1.3.5.2 (supports Averist 1.1.0.1 or later) - 12 January 2001 - release candidate 1
Dr. Dobb's Web Site Code Coverage Analysis in Perl by brian d foy
Is all of your Perl code actually executing? Are some statements invoked as expected? The Devel::Coverage module can give you the answer, but you've got to ask the right questions.
Perl comes with a built-in debugging mechanism that allows you to create your own debugger or use one created by someone else. Perl coders can also use the Devel::Coverage debugging module to determine just how much of a program actually executes. This testing process is called coverage analysis. The Devel::Coverage module is available on the Comprehensive Perl Archive Network (CPAN). I'll show you how to use this sort of analysis to actually test all parts of your target program.
You use coverage analysis while testing your code (and everyone tests their code, right?) to ensure that you have done everything that necessary to exercise as much of the code as possible. Proper coverage analysis by itself does not make your code better or your programs bulletproof, but allows you to focus on problems in your code or in the test cases by examining different coverage metrics.
You can use several different coverage analysis
Cultured Perl: Debugging Perl with ease. Catch the bugs before they bite by Teodor Zlatanov [Nov 2000]
Contents: |
The trouble with bugs |
Basic concepts of debugging |
Debugging terms |
The Perl debugger |
Devel::ptkdb |
Writing your own Perl shell |
Building an arsenal of tools |
Resources |
About the author |
Teodor Zlatanov walks you through both the built-in Perl debugger and CPAN's Devel::ptkdb. The Perl debugger is powerful but frustrating to navigate. CPAN's Devel::ptkdb, on the other hand, works wonders by simplifying code debugging and thereby saving hours of your precious time. In his discussion Zlatanov concentrates on explaining debugging methods and general concepts rather than looking at specific tools.
Bugs are as inevitable as death and taxes. Nevertheless, the following material should help you avoid the pitfalls of bugs. Some of the examples will require Perl 5.6.0 or at least 5.005. If you want to try the Emacs examples, you may also need to install the Emacs editor.
Perl Style Guide -- Each programmer will, of course, have his or her own preferences in regards to formatting, but there are some general guidelines that will make your programs easier to read, understand, debug and maintain.
ActiveState Perl Debugger -- great product, but only for Windows
Perl Debugger Built With a PerlTk User Interface [July 30,1998]
Regexevaluater.pl regexEvaluater.pl is a perl Tk script which was basically developed for the interactive testing and improving of regular expressions. It can be used for browsing and filtering of structured data (input separator $/ can be changed) too. It supports highlighting of matching text, export of perl's matching parentheses ($1, $2, ...), viewing of perl vars ($&, $+, ...) clipboard
Prettyprinting is a weak side of Perl: syntax is too complex. There are two major tools:
A Perl script called Perltidy, that does the job perfectly well.
DzSoft Perl Editor that contains a built-in beautifier
The Perltidy Home Page by Steven L. Hancock
Perltidy is a Perl script which indents and reformats Perl scripts to make them easier to read. If you write Perl scripts, or spend much time reading them, you will probably find it useful.
***** DzSoft Perl Editor Very decent shareware editor with elements of Integrated environment. Contains built-in beautifier ! by Sergey Dzyubenko, Alexander Dzyubenko, DzSoft Ltd.
New in v.5.1:
Features:
|
pb -- far from being perfect but better than nothing
#!/usr/bin/perl # 'pb' Perl Beautifier # Written by P. Lutus Ashland, Oregon [email protected] 5/20/96 # This script processes Perl scripts, cleans up and indents, like cb does for C # Be careful with this script - it accepts wildcards and processes every text file # that meets the wildcard criteria. This could be a catastrophe in the hands of the unwary. $tabstring = " "; # You may place any tab-stop characters you want here if($ARGV[0] eq "") { print "usage: file1 file2 etc. or wildcards (replaces originals in place)\n"; } else { foreach $filename (@ARGV) { if(-T $filename) { &process($filename); } } } sub process { $fn = $_[0]; undef $/; # so we can grab the entire file at once undef @infa; # prevent left-overs print STDERR "$fn"; open (INFILE,$fn); @infa = split(/\n/,); close INFILE; $/ = "\n"; # restore default open (OUTFILE,">$fn"); $tabtotal = 0; for (@infa) { s/^\s*(.*?)\s*$/$1/; # strip leading and trailing spaces $a = $_; # copy original string $q = $a; # i plan to modify this copy for testing $q =~ s/\\\#//g; # remove escaped comment tokens $q =~ s/\#.*?$//g; # remove Perl-style comments $q =~ s{/\*.*?\*/} []gsx; # remove C-style comments $q =~ s/\\\{//g; # remove escaped left braces $q =~ s/\\\}//g; # remove escaped right braces $q =~ s/\\\(//g; # remove escaped left parentheses $q =~ s/\\\)//g; # remove escaped right parentheses $q =~ s/\'.*?\'//g; # remove single-quoted lines # now the remaining braces/parentheses should be structural $delta = -($q =~ s/\}/\}/g); # subtract closing braces $delta += ($q =~ s/\{/\{/g); # add opening braces $delta -= ($q =~ s/\)/\)/g); # subtract closing parens $delta += ($q =~ s/\(/\(/g); # add opening parens $tabtotal += ($delta < 0)?$delta:0; # subtract closing braces/parentheses $i = ($tabtotal > 0)?$tabtotal:0; # create tab index $tabtotal += ($delta>0)?$delta:0; # add opening braces/parentheses for next print if(substr($a,0,1) ne "#") { # don't tab comments print OUTFILE $tabstring x $i; # "tab" out to position } print OUTFILE "$a\n"; # print original line } # -- for (@infa) close OUTFILE; if($tabtotal != 0) { print STDERR " Indentation error: $tabtotal\n"; } else { print STDERR "\n"; } } # sub process
3.4 Is there a pretty-printer (similar to indent(1) ) for Perl?
. . . If what you mean is whether there is a program that will reformat the program such as indent(1) will do for C, then the answer is no. The complex feedback between the scanner and the parser (as in the things that confuse vgrind) make [sic] it challenging at best to write a standalone Perl parser.
But I figured it could not be as difficult as this makes it sound. For one thing, Perl knows how to parse Perl programs, and the Perl source code is freely available, so Perl could conceivably be reworked into a Perl beautifier.
Alternatively, the GNU source code for the popular C language beautifier "indent" is also available, so another approach would be to rework its 7k lines of C to handle the Perl language.
But I knew there was an easier approach, that would not require reworking anybody else's existing code, or the use of a language other than Perl. I knew this because my quest for beauty had already led me to write a rudimentary C++ beautifier in a three command (sed | indent| sed) shell script (UNIX/World, August 1991, p. 134.), and later a more robust C++ beautifier in 140 lines of C and shell code (Dr. Dobbs' Journal, Dec. 1992, pp. 23s-27s).
These beautifiers certainly don't qualify as "standalone parsers" for C++, because they don't classify the program elements into meaningful units. But that doesn't prevent them from doing for C++ everything that indent and cb do for C! The trick is realizing that programs written in Language B can be successfully processed by beautifiers for Language A, if Language B bears a syntactic similarity to Language A, and if the Language B program can be temporarily disguised as Language A.
So with this C++ beautification experience under my belt, and a stubborn determination to prove that "Perl Beautification" could be accomplished if sufficient Hubris, Impatience, and Laziness could be mustered, I began writing in Perl the first fully functional "Perl Beautifier", pbeaut, in April of 1998 [1].
Beautification Strategy
As with its C++ predecessors, I approached the problem of writing pbeaut by capitalizing on the existence of mature beautification utilities for the C language, which has some fortunate syntactic similarities to Perl, and milking the UNIX filter model for all it's worth.
The basic approach, borrowed from my C++ beautifiers, is to use a pre-processor to disguise Perl code as C code, effect the beautification using standard C tools, and then convert the disguised Perl back to its original form using a post-processor.
The basic model is therefore:
PERL CODE ->
Perl-to-C Encoder ->
Standard C beautifier ->
C-to-Perl Decoder ->
BEAUTIFIED PERL CODE
Here is a listing of the first pbeaut program:
$ cat pbeaut #! /bin/sh # Tim Maher, Consultix. [email protected] # pbeaut, v .1 # these indent options work pretty well pencode $* | indent -npro -bl -bli0 -nce -npcs | pdecode $The encoder, pencode, examines every character of the Perl program, from first to last, and rewrites certain character sequences as necessary to disguise the Perl code as C.
The C beautifier, in this case GNU indent, inserts tabs to properly represent nesting levels, aligns parentheses and braces, inserts newline characters to split long lines into shorter ones, and generally fools around with the layout of the code to make it look more orderly and to emphasize the program's structure.
The decoder, pdecode, undoes the disguises crafted by pencode to reveal the hidden Perl program elements in their newly beautified context.
The current "production" version of pbeaut (version .62; 412 lines of code) communicates various types of information to and from the encoder and decoder and does extensive error checking, but its basic function is the same as the simple version shown above.
De-Obfuscation Testing
Where should one look to find the ugliest Perl code on the planet? Why the archives of past Obfuscated Perl Contests, of course, where contestants are rewarded for making their programs as inscrutable as possible (http://www.tpj.com/tpj/contest).
In this section, we'll examine the effects on Perl programs of C-style beautification using indent, as well as Perl-style beautification using pbeaut.
Here's a prize-winning entry from the 1996 contest:
$ cat caton #F. First place: Russell Caton # (Reduced in size to fit on one line.) $-=100;while((($@)=(getpwent())[2])){push(@@,$@);}foreach(sort{$a<=>$b}@@){(($_<=$-)||($_==($-+++1)))?next:die"$-\n";}After beautification with indent, it looks like this:
$ indent -npro -br -nce -npcs < caton # -br: brace on line with keyword#F. First place: Russell Caton $ -= 100; while ((($ @) = (getpwent())[2])) { push(@@, $ @); } foreach(sort { $a <=> $b } @@) { (($_ <= $ -) || ($_ == ($ - +++1))) ? next : die "$-\n"; }Perhaps surprisingly, the program layout looks pretty good, owing to the fact that Perl inherited many of its basic features from C (brace-delimited blocks, &&/|| conjunctions, semicolon line-termination, operator syntax, etc.).
On the other hand, the representations of two variables ( $- , $@ ) were altered by the insertion of a space between the symbols. Does this bother Perl?
$ perl -c caton caton syntax OK $ indent -npro -br -nce -npcs < caton > caton.ind; perl -c caton.ind caton.ind syntax OK $ perl -w caton.ind 101 $It doesn't bother Perl a bit! The program still produces the next available number from the /etc/passwd file (or NIS database). However, having the depictions of those variables messed up is definitely likely to annoy most (non-obfuscatory) Perl programmers!
After beautification with pbeaut, the program looks like this:
$- = 100; while ((($@) = (getpwent())[2])) { push(@@, $@); } foreach(sort{$a<=>$b} @@) { (($_ <= $-) || ($_ == ($-++ + 1))) ? next : die "$-\n"; }As you can see, the preservation of variable names has been achieved, along with a much more Perlish representation of the foreach loop.
Here's another unattractive winning entry from the 1996 contest:
#D. First place: Robert Klep # (Line breaks in original exactly as shown) $Y=-1.2;for(0..24){$X=-2;for(0..79){($r,$i)=(0,0);for(0..15){$n=$_;$r=($x=$ r)*$x-($y=$i)*$y+$X;$i=2*$x*$y+$Y;$x*$x+$y*$y>4&&last}print unpack("\@$n a" ,".,:;=+itIYVXRBM ");$X+=3/80}$Y+=2.4/25}Let's try beautifying this one with indent:
$ indent -npro -br -nce -npcs < klep > klep.ind Standard input:1: Warning: old style assignment ambiguity in "=-". Assuming "= -" Standard input:1: Warning: old style assignment ambiguity in "=-". Assuming "= -"$ indent -npro -br -nce -npcs < klep 2>/dev/null | tee klep.ind 1 $Y = -1.2; 2 for (0. .24) { 3 $X = -2; 4 for (0. .79) { 5 ($r, $i) = (0, 0); 6 for (0. .15) { 7 $n = $_; 8 $r = ($x = $ 9 r) * $x - ($y = $i) * $y + $X; 10 $i = 2 * $x * $y + $Y; 11 $x *$x + $y * $y > 4 && last 12 } 13 print unpack("\@$n a" 14 ,".,:;=+itIYVXRBM "); 15 $X += 3 / 80 16 } 17 $Y += 2.4 / 25 18 }
$ perl -c klep.ind klep.ind syntax OK $The "$Y=-1.2" assignment was correctly interpreted as "$Y = -1.2", rather than the archaic C "$Y =- 1.2", so no problem there. And once again, the program structure looks good, and it passed Perl's syntax check.
However, instead of drawing the default Mandelbrot fractal on the screen in ASCII characters, here's what the program does:
$ klep.ind $It seems that the degenerate range specifications (e.g, 0. .79) in the for loops, although syntactically acceptable, resulted in only one iteration of each loop, which wasn't enough to show much output.
The lesson to be learned here is that a faulty beautification process can produce code that is attractive but dysfunctional!
pbeaut, on the other hand, produces the following reworked version of this program, which functions correctly:
$ pbeaut -b 2 klep | cat -n # -b 2: opening brace on line with keyword 1 $Y = -1.2; 2 for (0 .. 24) { 3 $X = -2; 4 for (0 .. 79) { 5 ($r, $i) = (0, 0); 6 for (0 .. 15) { 7 $n = $_; 8 $r = ($x = $ # NOTE: extraneous newline here 9 r) * $x - ($y = $i) * $y + $X; 10 $i = 2 * $x * $y + $Y; 11 $x * $x + $y * $y > 4 && last 12 } 13 print unpack("\@$n a" # NOTE: extraneous newline here 14 ,".,:;=+itIYVXRBM "); 15 $X += 3 / 80 16 } 17 $Y += 2.4 / 25 18 }$This program looks pretty good, apart from the undesirable preservation of badly located newline characters from the original, which caused the splitting of the $r variable (lines 8-9) across a line break!
Although pbeaut tries to preserve programmer newlines by default, on the assumption they were sensibly placed, this behavior can be disabled through use of the -n (ignore newlines) invocation option:
$ pbeaut -n -b 2 klep | cat -n # -n: ignore newlines in original 1 $Y = -1.2; 2 for (0 .. 24) { 3 $X = -2; 4 for (0 .. 79) { 5 ($r, $i) = (0, 0); 6 for (0 .. 15) { 7 $n = $_; 8 $r = ($x = $r) * $x - ($y = $i) * $y + $X; 9 $i = 2 * $x * $y + $Y; 10 $x * $x + $y * $y > 4 && last 11 } 12 print unpack("\@$n a", ".,:;=+itIYVXRBM "); 13 $X += 3 / 80 14 } 15 $Y += 2.4 / 25 16 }That's better!
Testing with Perl Modules
It can certainly be fun decoding the purposely inscrutable scribblings of the obfuscatory programmers, but the real testing of pbeaut has focused on a different collection of programs - the modules of the standard Perl distribution. These 66 programs, totaling 20,247 lines of expert-grade Perl code, use most of the features of the language, in lots of different combinations.
Most of these programs can be successfully beautified. The others ( diagnostics.pm, getcwd.pl, perl5db.pl, CPAN.pm, English.pm ) cannot, due to their use of currently unsupported syntax features. (For example, semicolon delimiters with the substitution operator; see Current Limitations, below.)
How pbeaut Works
The job of pencode (currently about 1.7k lines of Perl5) is to make Perl code acceptable C code, using one of four techniques:
- encapsulating within C comments
- enclosing in quotes
- encoding symbols alphabetically; e.g., { -> LB
- leaving code unaltered (for material that can be properly handled by C-oriented rules)
We'll use a small program called fix to illustrate the encoding, beautification, and decoding processes.
$ cat fix #! /usr/bin/perl -wn # modify shebang pathname in input script # Written strangely to involve certain syntax features ${prog}='perl'; if ($. =~ /^1$/) {$_=s|^#! /usr/bin/$prog|#! /usr/local/bin/$prog|o;print;} else {print;} # other lines unaltered$ pencode fix | cat -n # show line numbers 1 /* _a_C #! _a_RMa\/usr_a_RMa\/bin_a_RMa\/perl -wn C_a_ */ 2 /* _a_C # modify shebang pathname in input script C_a_ */ 3 /* _a_C # written strangely to involve certain syntax features C_a_ */ 4 5 "_a_F_${prog}_F_a_"='perl'; 6 7 if ("_a_F_$._F_a_" _a_EQ_a_TD "_a_M_/^1$/_M_a_") # line wrapped for display {"_a_F_$__F_a_"="_a_S_s|^#! /usr/bin/$prog|#! /usr/local/bin/$prog|o_S_a_";print;} 8 else {print;} /* _a_C # other lines unaltered C_a_ */As you can see, the Perl comments were encapsulated within C comments (e.g., line 1), with a code sequence being inserted before each inner / . This is to guard against accidental termination of the C comment by material within the Perl comment. (Actually, the backslashes are only necessary for embedded slashes preceded by asterisks, but for simplicity all slashes are backslashed).
The basic encoding sequence, _a_ , and an ancillary preceding or following syntax-specific code, mark the sequences added by pencode to facilitate their later removal by pdecode. (NOTE: if _a_ appears in the input program, pbeaut will select a different sequence for use.)
To prevent indent from making bad decisions about formatting Perl symbol sequences, such as inserting spaces or newlines between them, certain ones are encoded with an alphabetic representation, such as EQ...TD for =~ (line 7).
For related reasons, in line 5, ${prog} gets quoted to prevent the C beautifier from splitting apart its components.
The job of pdecode (currently about 50 lines of Perl5) is to reverse the effects of pencode, by removing the C-comment "wrappers" encapsulating Perl comments, decoding the various encoded strings to their original forms, and so forth.
Let's look at the result of subjecting fix to the full beautification process:
$ nl -ba fix # original, pre-beautification 1 #! /usr/bin/perl -wn 2 # modify shebang pathname in input script 3 # written strangely to involve certain syntax features 4 5 ${prog}='perl'; 6 7 if ($. =~ /^1$/) {$_=s|^#! /usr/bin/$prog|#! /usr/local/bin/$prog|o;print;} 8 else {print;} # other lines unaltered $ pbeaut < fix | cat -n 1 #! /usr/bin/perl -wn 2 # modify shebang pathname in input script 3 # written strangely to involve certain syntax features 4 5 ${prog} = 'perl'; 6 7 if ($. =~ /^1$/) { 8 $_ = s|^#! /usr/bin/$prog|#! /usr/local/bin/$prog|o; 9 print; 10 } 11 else { 12 print; 13 } # other lines unalteredCompared to the original program, spaces have been inserted around the assignment operators (=) on lines 5 and 8, and the one-line code blocks on lines 7 and 8 of the original have been spread out over several lines (7-10, and 11-13).
Current Limitations
pbeaut is aware of many of its limitations, and it will report them to the user if one is encountered during processing, or if it is invoked with the -l option:
$ pbeaut -l LIMITATIONS OF pbeaut VERSION 0.62: Delimiters for match and substitution operators known to work: <{[(#/|!? (others might work, but they haven't been tested) Whitespace before some delimiters not supported (e.g., m /a/; s/// and tr/// are not allowed to change delimiters for the second part // sometimes formatted better if explicitly tagged as match, via m// q{}, qq(), etc., cannot have embedded }/) unless backslashed split must have white-space before first / (split //, not split//) Keyword "sub" and following subroutine name assumed to be on same line Here-Docs cannot omit Framing-Word (can't use blank line as terminator) TIPS: To disable beautification for a line, put "#LIT" at its end If you don't like the formatting of subs without parentheses, try adding them: sub foo() rather than sub foo (c) Tim Maher, CONSULTIX. [email protected] (206) 781-UNIX Contact author for restrictions on distribution and usageNOTE: Although there are numerous options to indent that can be used to enable or disable different types of program alterations, only a few of the various combinations have thus far been tested with pencode/pdecode.
For this reason, the current pbeaut only offers two choices of indent options: "-b 1" (braces on lines following keywords) and "-b 2" (braces on same lines as keywords).
Perl Beautifier Demo Page
To allow interested parties to experiment with it, I provided a pbeaut Demo Page on the World-Wide-Web for many months, which allowed me to obtain useful information about the strengths and weaknesses of the early versions.
Status Report
pbeaut is progressing rapidly, but is not yet fully reliable. In some cases, it generates Perl code that is syntactically incorrect, usually due to the introduction or removal of spaces and/or newline characters.
Fortunately, pbeaut incorporates safeguards to prevent the accidental corruption of the original program, including:
- presenting the beautified result to the standard output, rather than altering the original program
- running perl -c (syntax check) on the beautified code and reporting any syntax errors to the user
- reporting statistics on the input program and its beautified output, to facilitate detection of code loss
Even when errors are introduced, they are typically of a very minor nature, and are easily detected and fixed by an experienced Perl programmer.
Development and Testing Platforms
pbeaut was developed on Slackware Linux 3.0 using GNU indent 1.9.1, and has also been lightly tested under ULTRIX 4.3 using /usr/ucb/indent and /usr/bin/cb. I expect it to work just as well on other platforms having different versions of indent and cb, but that assumption is currently untested.
Availability
No version of pbeaut has yet been released, due to the author's reluctance to do so until it has been rewritten into a form more accessible to other programmers. Those in need of immediate beautification services are encouraged to try PerlTidy, which just came out in April, 2001, and from my preliminary testing looks pretty good.
Summary
pbeaut is a utility that can rewrite most Perl programs into compliance with an adjustable standard of presentation. Since the writing of this article, Steve Hancock's PerlTidy has become the de facto standard beautification utility, and we recommend it highly.
Footnotes
- [1]
- I am aware of the 5/20/96 pb program by P. Lutus Ashland, [email protected]. But unlike pbeaut, it does nothing but adjust indentation to properly reflect nesting levels, rather than offering the full power of C's indent and cb utilities.
All about Perl's SQL interface.
Berkeley DB C library source
www.oreilly.com -- Why I Promote Python -- a very weak paper of high educational value: I think that almost everything the author states about languages is wrong ;-). From one point of view the author does not recognize the right for existence of complex non-orthogonal languages, from the other he does not understand the value of TCL-style languages that presuppose usage of compiled language (C in case of TCL) for implementation of low level functions. From the third he does not recognize that C is a very elegant language that abstracts the most important features of contemporary CPUs. He also thing that there is free lunch and you can have all desirable features in one language (Python in the author opinion). As for scalability he is right about Perl (no clean way of interfacing with C and C++) and wrong about TCL which was designed to have a clean interface with C. And he naively believes in the power of OOP and consider creating a complex set of class the way to achieving scalability not the way to obscure the system to the point when it's easier to rewrite them from scratch then to use them and that for some reason this is more powerful approach the two level approach promoted by TCL. Anyway such an advertising of Python makes it highly suspect and forces to look Perl more attractive ;-)
Where languages like Basic, TCL, and Logo were artificially limiting, C++ and Perl are, in my opinion, artificially complex. Obviously there are many smart people out there preparing to send me an email claiming that the complexity "buys" them something valuable. I think that the cost is high.
I am not entirely naive: Computer programming is hard. It is precisely because it is hard that there is no excuse for adding artificial obstacles like modern languages rooted in the idioms of dead languages, and adding syntaxes so complex that humans cannot keep them in their head.
... ... ...
My primary criteria for decency--whether in programming languages, markup languages, or graphical systems--is scalability. By scalability, I mean two things: the ability to scale from easy to difficult problems and the ability for beginners and experts to be comfortable.
Consider an episode from my own life. I was around nine or ten years old and my father taught me how to do things on our Apple II using Basic. My dad was always much more of a hardware rather than software guy. Whenever I would tell him I wanted to do something more complex than we could find in the Basic manual, he would say, "You have to do that in assembly language, and assembly is too hard for a kid." He didn't mean to shut me down but he also didn't know 6502 assembly language himself and was not in much of a position to teach it to me.
The effect, though, was that my travel down the path to programmer enlightenment was delayed for several years. The Basic dialect was (like today's "TCL") designed for beginners and had many arbitrary limitations built in. Assembly was designed for programmers and made no concessions to usability, intuitiveness, or learning. Neither was scalable.
Today we have Perl, TCL, and C++: all non-scalable in their own way. C++ and Perl only make sense if you have a particular programming background. If you did not come from the "Unix tradition", many of their conventions and idioms seem alien.
Consider the modern nine-year-old boy trying to configure and extend his Linux system. He would find that many string-processing programs are inexplicably written in C: one of a very few languages that does not even have a first-class string data type! Most of the GUIs would be written in C++, despite the inflexibility of the language. Many other programs are written in a variety of illegible dialects within the family of languages called "Perl".
C and assembly have historical reasons for being so low-level and thus difficult to use and learn. It makes sense sometimes to trade usability for performance. C++ and Perl have no such excuse. They are cryptic and complex because of an overemphasis on backwards compatibility and plain, old-fashioned poor design.
Where languages like Basic, TCL, and Logo were artificially limiting, C++ and Perl are, in my opinion, artificially complex. Obviously there are many smart people out there preparing to send me an email claiming that the complexity "buys" them something valuable. I think that the cost is high.
When you use some wickedly cool and obscure feature of the language, you reduce the number of potential readers of your code. Ideally the language would encourage you to concentrate your creativity on high-level design. Choosing algorithms and data structures is hard enough. Keeping all of the library functions in your head is also tricky. On top of all of this, programmers should not need to decipher obscure core language features. Why make life harder for those who will follow you?
Personally, I cannot stand this design aesthetic, because it divides the world into "programmers" and "non-programmers". My dream is a world wherein all but the very lowest levels and tightest loops of programs are written in a language that is so simple that it can be taught in primary school as a first language; where every word-processor user who can write a macro can at least try to dive into their word processor's source code to fix a bug, because the macro language is also the implementation language.
We know that such a language exists. Python is easy enough to be a first language and powerful enough to write object databases (like ZODB) and in-memory relational database engines (like Gadfly). And yet, you do not have to come to grips with a complex and difficult type system to use it, and there are few magical variables and functions. I believe it to be as flexible as Smalltalk and as feature-full as Perl; and yet it is as easy as Basic or TCL.
... ... ...
Python may or may not be the language that brings about a Computer-Programming-for-Everybody world. But it is currently the best contender. When there is a better horse, I'll switch my bet. The hard part for a competitive system is building a sophisticated class library; but if the language is good enough, it will find early adherents that will do the work, as Python has.
A hint to would-be language developers: If your language runs on the JVM as JPython does, you get the benefit of the Java library "for free". Being Open Source is also a necessity today.
Power, elegance, simplicity, equality, liberty, fraternity: This is heady stuff, and it explains the evangelical tone of some Python programmers. I promote Python because doing so is the right thing.
CPAN
US Mirrors | Europe Mirrors |
CPAN [Texas] | CPAN [funet.fi] |
CPAN [California] cdrom.com | CPAN [ruhr-uni-bochum.de] |
CPAN [New York] | CPAN [pasteur.fr] |
CPAN [Massachusetts] | CPAN [ruu.nl] |
CPAN [sunet.se] | |
CPAN [sunsite.auc.dk] |
Etc
CGI Scripts
see also Index of PerlRing
Second Perl conference [added November 4, 1998]
New Architec -- Uploading Files and Sending MIME Mail
Most of us have a junk drawer in our house. You know, the one with the random bits of discarded stuff we hope will come in handy in the future, like the last part of a roll of duct tape, a couple of nuts and washers that for some reason weren't needed when we reassembled the shelves this time, and so on. When something needs to get done, we rummage through the drawer looking for the right part or widget, only to pass the same useless items time after time. But every once in a while we find something that's actually useful and we think, "Yeah, I'm so glad I saved that!"
The Perl Shell is a shell that combines the interactive nature of a Unix shell with the power of Perl. The goal is to eventually have a full featured shell that behaves as expected for normal shell activity. But, the Perl Shell will use Perl syntax and functionality for for control-flow statements and other things.
Perl Shell 0.003 Gregor N. Purdy - November 23rd 1999, 18:03 EST
The Perl Shell (psh) is an interactive command-line Unix shell that aims to bring the benefits of Perl scripting to a shell context and the shell's interactive execution model to Perl.
Changes: This version of the Perl Shell adds significant functionality. However, it is still an early development release. New features include rudimentary background jobs handling and job management, signal handling, filename completion, updates to history handling, flexible %built_ins mechanism for adding built-in functions and smart mode is now on by default.
Society
Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers : Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism : The Iron Law of Oligarchy : Libertarian Philosophy
Quotes
War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda : SE quotes : Language Design and Programming Quotes : Random IT-related quotes : Somerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose Bierce : Bernard Shaw : Mark Twain Quotes
Bulletin:
Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 : Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law
History:
Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds : Larry Wall : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOS : Programming Languages History : PL/1 : Simula 67 : C : History of GCC development : Scripting Languages : Perl history : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history
Classic books:
The Peter Principle : Parkinson Law : 1984 : The Mythical Man-Month : How to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite
Most popular humor pages:
Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor
The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D
Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.
FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.
This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...
|
You can use PayPal to to buy a cup of coffee for authors of this site |
Disclaimer:
The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.
Last updated: March 12, 2019