Previous month:
August 2021

September 2021

How to use Perl on an HP 3000

By Dave Lo

Perl is an interpreted language that is the brainchild of Larry Wall. He continues to develop and guide the language, which, through the help of the net community, is available on virtually every computer platform, from Apple’s Macintosh to MPE.

Perl, officially known as either Practical Extraction and Reporting Language or Pathologically Eclectic Rubbish Lister, is a popular language for implementing web page CGI scripts, processing string data, even system administration. The official Perl web site is www.perl.com.

However, Perl is much more than a sometimes-odd-looking web scripting language. It has enough power to be a full programming language. One glance at some of the O’Reilly Perl books will testify to that (Perl for Bioinformatics, Perl for System Administration, Perl for Website Management).

If you think of perl as a shell-like programming language that evolved from quick-and-dirty handling of text, lists, associate arrays, and regular expressions, then you’re already thinking Perl. Let’s dive in!

Scalar variables

0 # Perl has no line numbers, they’re here for reference only
1 $num = 123;
2 $str = “abc”;
3 print “number=$num string=$abc”;

Line 0 is a single-line Perl comment, which are similar to Unix shell comments. There are no multi-line comments.

Perl is not a strictly typed language, so a variable can hold either numeric or string values. Also, no declarations of variables are needed before they are used. Line 1 and 2 assign a number and a string. These type of variables are known as scalar variables (they hold a single primitive value), and their names are prefixed by a $ sign. One characteristic of Perl is that all variables names have a prefix character such as $. This may seem strange, but not when you think of similarities to Unix shell scripts.

List variables

1 @list = (12.3, “abc”, 4..6);
2 foreach $i (@list) {
3 print “$i\n”;
4 }
5 $count = @list;
6 print “There are $count items\n”;

Another fundamental variable type in Perl is List. Line 1 shows the assignment of a list variable, whose name is prefixed with a @ sign. A list variable is like a 1-dimensional array. But unlike strictly typed languages, a list in Perl can contain mixed types of data. Here, the list contains 5 values: the number 12.3, the string “abc”, and numbers 4, 5, and 6.

Lines 4-6 are a typical way of looping through all the items in a list, using the foreach construct. In line 5, notice that literal strings in double quotes can contain variables that are dereferenced.

Line 7 may initially look like an error (assigning a list variable to scalar variable), but it is a common occurrence in Perl and shows an important concept: context. Think of context as fancy type-conversion. Here, because the left-hand-side of the assignment is a scalar variable, the right-hand-side must also be scalar. So the list variable is “evaluated in a scalar context”, which does the convenient thing of returning the number of items in the list. You’ll discover that Perl has many of these types of conveniences built-in.

We could also have accessed the list in a traditional array-like fashion by numeric indexing. Like C, Perl starts array indexes at 0.

9 for ($i=0; $i<@list; $i++) {
10 print “$list[$i]\n”;
11 }

Note in Line 10 that we prefixed the list with a $. This is because list[$i] is a scalar value, so a scalar prefix is needed. Another important point is that scalar and list variables names are in different namespaces. This means you can simultaneously have a $abc scalar variable and @abc list variable. Use this feature carefully, otherwise you end up write hard-to-understand code such as $abc = $abc[$abc].

Hash variables

A powerful feature in Perl are hashes (otherwise known as associate arrays). Hashes are like arrays that are indexed not by sequential numbers, but by string value. It is a simple way to store key-value pairs.

$review{“Monsters Inc.”} = “funny and original”;
$review{“Harry Potter”} = “true to the book”;
$review{“Lord of the Rings”} = “also true to the book except for Arwen”;

Here is an example of parsing a string similar to those commonly returned from an HTML form:

1 $line=”option=1&company=Robelle&product=Qedit,Suprtool”;
2 @pairs=split(/&/,$line);
3 foreach $item (@pairs) {
4 ($name, $value) = split(/=/,$item);
5 $form{$name} = $value;
6 }
7 @list = keys(%form);
8 foreach $name (@list) {
9 print “$name = $form{$name} \n”;
10 }

In Line 2 and 4, the split function takes a regular expression (although we are using it here just for a simple string search) and a string, finds the substrings that are separated by the regexp, and returns a list of those sub-strings. So in Line 2, we are looking for the substrings separated by an ampersand &. Split returns this list of three strings:

option=1
company=Robelle
products=Qedit,Suprtool
In Line 4, the split works in a similar way to break up “option=1” into a list of two elements (“option”, “1”). Notice that Perl allows simultaneous assignments of several variables. The assignment puts the first element in $name and second element in $value.

In Line 5, the assignment to a hash looks almost like assigning to an array assignment, except that curly braces are used instead of square brackets

In Line 7, the keys function returns a list of all the key values in a hash (“option”, “company”, “product”). Notice that a hash is prefixed by a % sign when used in hash context. If you wanted to get all the values in a hash, you would use the values function, which would have returned (1, “Robelle”, “Qedit,Suprtool”)

Perl on MPE/iX

Perl for MPE/iX is available for download from the HP Jazz Web site: jazz.external.hp.com/src/hp_freeware/perl/. Perl was ported to the HP 3000 by Mark Bixby. Here are some notes on Perl/iX from the Jazz Web site:

“The following prerequisites apply to Perl on MPE/iX: MPE/iX 6.0 or greater. This software has not been tested on versions earlier than 6.0. Approximately 325,000 sectors of available disk space.” Perl has been linked to use the shared libraries /lib/*.sl and /usr/lib/*.sl; if these libraries are missing or have restrictive permissions then Perl will not run. These libraries are a standard part of MPE FOS starting with 6.0. If for some reason you are missing these libraries, you can recreate them by logging on as MANAGER.SYS and then running the shell script /PERL/PUB/mpebin/LIBS.hp3000.

Integration With MPE

A few MPE-specific modules are starting to become available for Perl. The following is a partial list; none of these are bundled with this distribution, so if you want to play with them you’ll have to download and build them yourself:

MPE::CIvar — Ken Hirsch’s interface for MPE/iX JCWs, CI variables, and the HPCICOMMAND intrinsic. Please see invent3k.external.hp.com/~MGR.HIRSCH/CIvar.html for more info.

MPE::IMAGE — Ted Ashton’s interface for MPE/iX TurboIMAGE databases. Please see search.cpan.org/search?dist=MPE-IMAGE for more info.

Web Resources for Perl

These include www.perl.org, the Perl user community; www.perl.com, O’Reilly’s official Perl home; and www.cpan.org, the Comprehensive Perl Archive Network for perl distribution, doc, modules. If you have trouble installing packages from CPAN, read Ken Hirsch’s installation tips at invent3k.external.hp.com/~MGR.HIRSCH/cpan.html

O’Reilly books

• Learning perl - A good introduction to the language

• Programming perl - Known as the “camel book”, it is the definitive Perl reference written by the authors of Perl

• perl cookbook - Solutions for common operations. For example, Problem: How to do something to every word in a file?

Solution: Split each line on whitespace:

while (<>) {
for $chunk (split) {
# do something with $chunk
}
}

 


The HP 3000's Earliest History

By Bob Green

With HP announcing its latest sunset for the HP 3000 in 2007, I thought some of you might be feeling nostalgic for some history. The original 16-bit HP 3000 (later called “the Classic”) was released in 1972 and re-engineered into a 32-bit RISC processor in the 1980s.

Background (1964-1969)

The HP 2000 Time-Shared Basic System (1968) was HP’s first big success in computers. The 2000 line was based on the 2116 computer, basically a DEC PDP-8 stretched from 12 to 16 bits. HP inherited the design of the 2216 computer when it acquired Data Systems, Inc. in 1964 from Union Carbide. The 2000 supported 16 to 32 time-sharing users, writing or running BASIC programs.

This product was incredibly successful, especially in schools. The original 2000A system was created by two guys working in a corner: Mike Green, who went on to found Tandem much later, and Steve Porter, who also went on to found his own computer company. Heavy sales of the 2000 brought the computer division of HP its first positive cash flow, and with it the urge to “make a contribution.” The engineers and programmers in Cupertino said to themselves, “If we can produce a time-sharing system this good using a junky computer like the 2116, think what we could accomplish if we designed our own computer.”

Abortive First Try (1969-1970)

The project to design a new computer, code-named “Omega,” brought new people into the Cupertino Lab, people who had experience with bigger operating systems on Burroughs and on IBM computers. The Omega team came up with a 32-bit mainframe: It was stack-oriented, had 32-bit instructions, data and I/O paths, eight index registers, up to 4 megabytes of main memory, up to four CPUs sharing the same memory and bus, both code segmentation and data segmentation, and a high-level systems programming language instead of Assembler; it was capable of multiprogramming from the start, and had support for many programming languages (not just BASIC as on the 2000).

The Omega was designed to compete with big CPUs. But Omega looked too risky to management. HP would have had to borrow long-term funds to finance the lease of machines to compete directly with IBM. So it was cancelled. Some of the Omega architects left HP, but most stayed. “Several people who remained took to wearing black-velvet armbands, in mourning for the cancelled project,” according to Dave Packard in his 1995 book, The HP Way.

The 16-Bit Alpha (1970-71)

Most of the Omega team were re-assigned to the Alpha project. This was an existing R&D project to produce a new 16-bit computer design. The Omega engineers and programmers were encouraged to continue with their objectives, but to limit themselves to a 16-bit machine. Alpha was Omega squeezed into 16 bits: 128 KB of main memory (max), one index register, and Huffman coding to support the many address modes desired (P+- for constants, DB+ for global variables, Q- for parameters, Q+ for local variables, and S- for expression evaluation).

Same People, Smaller Hardware, Bigger Software

The original design objectives for the Omega Operating System were limited to multiprogrammed batch. The Omega designers put off time-sharing to a later release that would be supported by a front-end communications processor. The cancellation of Omega gave the software designers another year to think of features that should be included in the Alpha Operating System.

As a result, the software specifications for this much smaller machine were now much more ambitious that those for the bigger Omega. They proposed batch, time-sharing and real-time processing, all at the same time, all at first release, and all without a front-end processor.

The instruction set of the Alpha was designed by the systems programmers who were going to write the compilers and operating system for the machine. The prevailing “computer science” philosophy of the day was that if the machine architecture was close to the structure of the systems programming languages, it would be easier to produce efficient, reliable software for the machine and you wouldn’t need to use Assembler (that is, a high-level language would be just as efficient and the code would be much easier to maintain).

The Alpha was a radical machine and it generated infectious enthusiasm. It had virtual memory, recursion, SPL instead of Assembler, friendly MPE with consistent batch and online capabilities instead of OS-360 with its obscure command syntax, variable-length segments instead of inflexible pages, and stacks instead of registers. The Alpha was announced as the HP 3000 with a fancy cabinet of pizza-oven doors, available in four colors. Prospective users were assured that it would support 64 users in 128 KB of memory.

Harsh Realities (1972-73): 200 Pounds of Armor on a 90-Pound Knight

I worked at Cupertino at the time and was assigned to coordinate the production of the ERS (External Reference Specifications) for the new software. I was as excited as everyone else. The first inkling I had that the HP 3000 was in trouble came in an MPE design meeting to review the system tables needed in main memory. Each of the ten project members described his part of MPE and his tables: code segment table, data segment table, file control blocks, etc. Some tables were memory-resident and some were swappable. When the total memory-resident requirements were calculated, they totaled more than the 128 KB maximum size of the machine.

MPE wouldn’t fit, so everyone squeezed: The programmers squeezed in 18-hour days, seven days a week trying to get MPE to work. Managers were telling their bosses that there was no problem, they just hadn’t had a chance to “optimize” MPE yet. When they did, the managers maintained, it would all turn out as originally promised. So marketing went on selling the machines to the many existing happy users of the HP 2000. As the scheduled date for the first shipment approached, the Cupertino factory was festooned with banners proclaiming “November Is a Happening.”

The first HP 3000 was shipped November 1, 1972 to Lawrence Livermore Hall of Science in Berkeley, California. But it was incomplete: It had no spooling, no real-time, etc. It supported only two users, and it crashed every 10 to 20 minutes. Customers who had been promised 64 terminals and who were used to the traditional HP reliability became increasingly frustrated and angry.

Eventually the differences between the HP 3000 reality and the HP 3000 fantasy became so large and well-known that there was even a news item in Computerworld  about it — the first bad press ever for HP. Bill and Dave were not amused. The product was withdrawn from the market for a short time.

Struggling to Restore Lost Credibility (1973-74)

Hewlett-Packard had no experience with bad publicity from low-quality products. Paul Ely was brought in from the successful Microwave Division to straighten out the computer group. The first priority was to help out the existing HP 3000 users, the ones who had trusted HP and placed early orders. Many of them received free 2000 systems to tide them over until the 3000 was improved. The second priority was to focus the programmers’ energy on fixing the reliability of MPE.

Once the HP managers realized the magnitude of the 3000 disaster, the division was in for lean times. Budgets and staffs that had swollen to handle vast projected sales were cut to the bone. Training, where I worked, was cut from 70 people to fewer than 20 in one day. HP adopted a firm “no futures” policy in answering customer questions (a policy that lasted for years after the HP 3000 trauma, but was forgotten by the time of the Spectrum-RISC project). The new division manager was strictly no nonsense. Many people had gotten in the habit of taking their coffee breaks in the final-assembly area, and kibitzing with the teams testing the new 3000s. Ely banned coffee cups from the factory floor and instituted rigorous management controls over the prima donnas of the computer group.

By continuing to work long weeks, the programmers managed to reduce MPE crashes from 48 a day to two, and to increase users from two to eight. Marketing finally took a look at what the 3000 could actually do, and found a market for it as a replacement for the IBM 1130. They sold the 3000 as a machine with more software capability than an IBM 1130 that could be available to a number of users at once instead of just one. Eventually the 3000 became a stable, useful product. To my mind, this happened when someone discovered the “24-day time bomb” bug. If you kept your HP 3000 running continuously for 24 days (2^31 milliseconds) without a shutdown or a crash, the internal clock register would overflow and the system would suddenly be set back by 25 days!

The Comeback: Fulfilling the Promise (1975-76)

The original 3000 had a minimum usable memory size of 96 KB and a maximum of 128 KB — not much of an expansion. The Series II went beyond that 16-bit limitation by adding “bank” registers for each of the key pointers (that is, code segment, data segment, and so on). Thus the Series II could support up to 512 KB, a much more reasonable configuration for the software power of MPE.

The choice of SPL as the HP 3000 machine language instead of Assembler truly began to pay off now in an avalanche of excellent software: The IMAGE database (again, two guys working in a corner: Jon Bale and Fred White) was soon joined by compilers for COBOL and RPG, a screen handler, and other tools to support transaction processing.

Concurrent, consistent batch and time-sharing was now a reality and the goal of concurrent real-time was finally dropped as unrealistic. The HP 3000 hardware now matched the software written for it. Business users discovered that the 3000 was great for online transaction processing; they dragged Hewlett-Packard firmly into the commercial information processing world.

At last, with the Series 64 in 1982, the 3000 reached the original target of 64 users on a single machine.

P.S. For another interesting history of the HP 3000, read HP’s Early Computers, Part Three: The Strongest Castle: The Rise, Fall and Rise of the HP 3000 by Chris Edlar