Ok, Let's begin.
Background:
I program, or have programmed, in C/C++, SQL, Fox & Clipper,
Assembly (8086, 8080, Z80, Z8, 6809), Forth, Basic, etc.
I'm always looking for a better lever. Accomplish the same or
more with less effort.
The expectations of users have largely changed, with more
emphasis on GUI and internet.
Knowing that I would have to learn something new to meet
this new expectation, I looked at a variety of languages and
development environments.
Finding that Perl is 1) cross platform, 2) free, 3) a widely
respected tool, accepted as a standard in the world of
Unix and Linux, 4) open source, 5) stable, 6) valid in both
command line and GUI, 7) the standard in CGI programming,
8) database friendly via DBI, 9) very well documented with
many titles available, and 10) available everywhere ...
I decided to give it a try.
Perl's ancestry:
Perl means "Practical Extraction and Reporting Language"
and/or "Pathologically Eclectic Rubbish Lister."
Larry Wall (who wrote Perl) endorses both meanings.
Perl is a fusion of a number of concepts familiar to anyone
with a Unix/Linux background. It uses a structure very similar
to C (white space neutral, semicolon separated, brace blocked,
if/else, for, do, while) and adds some other control structure
stuff not found in C (elseif, until, last/next/redo, block labels,
unless, foreach). It features VERY strong string processing,
making good use of "regular expression" technology. It has
arrays, and some exotic array features. More recently, GUI
features have been added in a module called "/tk" (no I don't
know why). And it has "implied variables" that simplify much
program notation (once you get used to that).
So what does that mean to someone familiar with DOS or
Windows? And what the heck is a "regular expression?"
DOS is largely descended from CP/M with certain features
borrowed from Unix. They share some common attributes.
However, DOS is much less than it could have been. When
you begin to explore Linux or Unix, you discover large gaps
between what DOS is and what it could be.
The good news is that learning that command environment
is a series of incremental steps upward.
You can use Perl under DOS (you lose some of the more
advanced features), or you can use Perl under Win32.
Also, if you want to get a better look at Unix on your
Win32 machine, you can download UWIN. Perl works in
this environment as well. (Perl also runs on Mac ...)
Now, about that "regular expression" thing. In the
beginning was the printing terminal. Electric typewriters
and teletype (telex) machines. The screen was made
of paper. There was no "full screen" text editor or
"wysiwyg" word processor. One did not hold down the
arrow keys and scroll up and down through a document.
The "cursor" was a little red mark on the typewriter's
print head. The "home" and "end" keys and "pgup" and
"pgdn" keys didn't exist. Later models of printing
consoles had more keys, but still no glass screen.
Text processing was done using programs called "line
editors" or "text editors," and navigating in your text
required being able to use the regular keys not only
to type text, but to issue commands to the editor.
In this setting, to be productive, editors were written
to have very terse commands (usually a single letter
or symbol).
One of the notations that developed in this context of
very economical expression was a short and precise
symbolic way of describing parts of text strings and
relationships of these string parts for searching and
substitution purposes. Rather than say simply find
'formation' (which you could), you might want to look
for the word 'formation' after the word 'rock' on a line
ending with 'blue' without doing a bunch of "find next"
searches. You want to match a pattern, rather than
a simple string.
Regular expressions supply a compact way to say
that. When composing regular expressions, symbols
are used to mean special things. A dot (.) is used
to allowing matching with any character. A symbol
meaning "some, maybe" is the asterisk (*). To say
"at the end of a line" the dollar sign ($) is used.
Patterns are enclosed in pairs of slashes (/). Thus,
in the above example, the way to say "find the word
'formation' on a line where 'rock' comes before it and
the line ends with 'blue' " is this:
/rock.*formation.*blue$/
and to substitute 'outcropping' for 'formation' while
leaving 'rock' and 'blue' alone, we introduce parens
to capture parts of the expression and represent
them in the substitution, thus:
s/\(rock.*\)formation\(.*blue\)$/\1outcropping\2/
(the \1 represents rock.* and \2 represents .*blue).
No, we're not going to make this a "grep" tutorial
(grep= general regular expression parser).
The point is, the notation for powerful string operations
is brief and precise, yet allows you to specify fuzzy
conditions like "somewhere before."
This kind of power gives Perl quite a punch.
What was that about "implied variables" up there?
We'll talk about that as we go on.
Right now I have to get some sleep.
~~ Garry
==========
Thread Origin
==========
I had asked:
>
> Would there be any interest in some observations
> on Perl, and its relation to SurvPC, or will that
> bore you guys to tears?
"Eko Priono" <[EMAIL PROTECTED]> wrote:
>
> Perl is C-like, so I guess some programmers here
> will be interested...
"Heimo Claasen" <[EMAIL PROTECTED]> wrote:
>
> Reckon I have to learn it anyway, <sigh>.
> So for my part: go ahead, Garry !
To unsubscribe from SURVPC send a message to [EMAIL PROTECTED] with
unsubscribe SURVPC in the body of the message.
Also, trim this footer from any quoted replies.
More info can be found at;
http://www.softcon.com/archives/SURVPC.html