View on GitHub

Stagyrite

šŸŖ Perl Kit

Other developer platform

Q: Is there any other developer platform where I can find those sources?

A: Yes, itā€™s on Bitbucket. This process of importing Perl 1 has even its history. Perl 1 was pushed to Bitbucket a long time ago. The author of the push made that particular version better in terms of compiling errors. Then, the repository was removed from Bitbucket, and people pushed it to GitHub. That GitHub repository was left almost intact and forked this year. The forked repositories were fixed to compile. Finally, the valid code was imported back to Bitbucket.

Compiling

Q: How to compile it?

A: Start by installing the required packages (ā€˜gccā€™, ā€˜yaccā€™ and ā€˜makeā€™) in a target system. It might not compile when you have an old version of make. If youā€™re on Cygwin, check out that you have GNU Make 4.4.1 or so.

Fetch the files from GitHub. The project canā€™t built when sources have CRLF line endings. Either donā€™t fetch with CRLF line endings or convert line endings to LF.

git config --global core.autocrlf false
git init
git remote add origin https://github.com/Stagyrite/Perl-1.0.git
git pull origin main

Now you can compile a ā€˜perlā€™ program.

./Configure
make depend
make

The same can be done in the ā€˜x2pā€™ subdirectory.

cd x2p
cp ../Configure .
./Configure
make depend
make

One might want to run all tests from the ā€˜tā€™ directory, as those all pass, at least on Cygwin.

Known bugs

Q: Are there any known bugs or limitations?

A: Yes, there are, and hereā€™s an example. Letā€™s assume you check how much memory ā€˜postgresā€™ uses. This can be done by executing: echo "q" | top -b | grep "postgres" | awk -F " " '{ memory += $10 } END { print memory } Letā€™s assume the numbers were: 0.2, 3.6, 3.5, 0.1, 0.0, 0.0, 3.7, 1.0, 0.6, 0.4, 2.4, 2.5, 2.3, 2.5, 0.4, and 0.4. The output number is 23.6, and itā€™s a valid percentage value. Hereā€™s a Perl 1 program generated with the Awk to Perl translator from the ā€˜x2pā€™ subdirectory. Itā€™s a slightly modified version of it.

#!./perl
eval '$'.$1.'$2;' while $ARGV[0] =~ /^([A-Za-z_]+=)(.*)/ && shift;
                        # process any FOO=bar switches

$, = ' ';               # set output field separator
$\ = "\n";              # set output record separator

while (<>) {
    ($Fld1,$Fld2,$Fld3,$Fld4,$Fld5,$Fld6,$Fld7,$Fld8,$Fld9,$Fld10) = split(' ');
    $memory += $Fld10;
}

print $memory;

The output number is now 23.599999999999997868, and that is a slightly different result. The difference is 0.000000000000002132.

Other versions of Perl 1

Q: Are there any other repositories with Perl 1 available?

A: Yes, there are other versions of Perl 1, and other pages as well. Hereā€™s a quite complete list of them.

  1. GitHub/Stagyrite/Perl-1.0
  2. GitHub/eltikia/Perl-1.0
  3. GitHub/Stagyrite/perl-1.0_16
  4. GitHub/eltikia/perl-1.0_16
  5. CPAN/perl-1.0_16
  6. GitHub/kaworu/perl1
  7. GitHub/eltikia/perl1
  8. ETLA/perl1

What are you doing?

Q: Can you explain what has been done with the Perl 1 repository? I mean the recent commits made by @Stagyrite.

A: The refreshed Perl 1 is supposed to run on modern operating systems. It wasnā€™t even compiling at first. A non-compiling AWK to Perl translator was also taken care of. It now compiles on several modern operating systems, and that includes Windows (Cygwin). Multiple compiler warnings were eliminated.

A subroutine example

Q: Can you give us an example of a subroutine in Perl? Iā€™m studying for a Java exam and Iā€™d like to know more. Hereā€™s a quotation from a handbook.

Different languages handle parameters in different ways. Pass-by-value is used by many languages, including Java. [ā€¦] The other approach is pass-by-reference. It is used by default in a few languages, such as Perl.

A: Letā€™s consider what the handbook says, and we need both Perl 1 and Perl 5 interpreters to find out how it works.

No call-by-reference in Perl 1

A pass-by-reference example wouldnā€™t work in Perl 1, and here is a good try.

sub trySwap {
    $temp = $_[0];
    $_[0] = $_[1];
    $_[1] = $temp;
}

$a = 1;
$b = 2;
do trySwap ($a, $b);
print $a;
print $b;

This Perl 1 program prints 12 which is different from what we expect.

Call-by-reference in Perl 5

Call-by-reference is the default Perl 5 mechanism, just like the handbook states.

sub swap {
    $temp = $_[0];
    $_[0] = $_[1];
    $_[1] = $temp;
}

$a = 1;
$b = 2;
swap ($a, $b);
print $a;
print $b;

It prints 21 just like expected.

Something similar in Perl 1

Hereā€™s a traditional although sophisticated Hello World program.

#!./perl

sub printSwapped {
    $temp = $_[0];
    $_[0] = $_[1];
    $_[1] = $temp;
    print $_[0];
    print $_[1];
}

$a = "world\n";
$b = "hello, ";
do printSwapped( $a, $b );

Its output is ā€œhello, worldā€ printed in a single line.

Content about Perl 1

Q: Is there any content created about Perl 1?

A: Yes, there is. First, Iā€™d like to mention the original README file. Itā€™s from the year 1987 when the Perl 1 was created. Second, you might want to see a README.chastai file. This is from the year 2014. In the year 2024, a new site has been created. It provides my Perl Geek Code, as well as the discussions. Nevertheless, you should take a look at the code, if interested. Knowledge of Perl programming and compilers would be helpful in this particular task.

A reason of being

Q: Is there any reason of being for this project? Can you tell us what is it all about?

A: Iā€™d call developing the Perl 1 compiler my historical approach to the Perl programming language. I want to learn Perl and Raku (Perl 6), and therefore I have to choose a way. These are the personal reasons for the project. Its reason of being is that compilers should be fresh (e.g., themselves compiling). Itā€™s also about something one can call poetry, and I mean poetry when it provides a quick result. It would certainly take longer to refresh some other projects (e.g. Linux kernel ver. 0.01). In Raku, one can get a result that takes fewer lines of code than in Java, as one can see in a separate discussion.

First impression

Q: Can you give us your first impression of the Perl 1 compiler?

A: My first impression would be that whatā€™s in Perl 1 is often bogus. Itā€™s from the year 1987, and therefore you must be careful to use it anyhow. Numerical operations can lead to an error unexpected nowadays. Perl 1 isnā€™t written in Perl, contrary to new versions of Perl that are written in Perl. One should know translation methods to understand it better and dig into what YACC does. The code would give a pretty good impression to somebody skilled in Perl programming and compilers.

Real user feedback

Q: Did you receive any feedback from real users?

A: Yes, I received an email when the project started to compile again. At the point of stating the obvious, the whole development process was done in the year 1997. Nevertheless, the development continues, as Perl 1 doesnā€™t compile without warnings. There have been a social media post about this project, but I donā€™t try to maintain any contact.

Background in Perl programming

Q: Whatā€™s your background in Perl programming?

A: I had a Perl course when I studied Computer Science at the University of Wrocław. Later I used multiple scripting languages during my studies to solve mathematical assignments. When at work, I tried modern languages like Ruby, Python, and Scala. Those are similar to Perl, although I still use Java for practical text extraction. My Perl Geek Code is turned into tooltiped links with a Java project, although the code was based on a Perl converter.

Starting Perl

Q: What would you recommend to a person who wants to learn Perl?

A: If you need to learn Perl, a full academic course is what you need. In the particular case of a person who likes to learn Perl, Iā€™d recommend installing a Linux operating system. Iā€™d also give her some books about Perl and Raku to read. One can also join an online paid course.

My approach is historical because I also try the Perl 1 compiler, although I donā€™t recommend it to everyone. Itā€™s also related to learning a foreign language because I got books in German. I want to learn German, and therefore I read them.

āš›šŸ…šŸ¦…šŸ¦