Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Mark Leighton Fisher (4252)

Mark Leighton Fisher
  (email not shown publicly)

I am a Systems Engineer at Regenstrief Institute []. I also own Fisher's Creek Consulting [].
Friday December 07, 2007
01:05 PM

You Can Write Perl in Any Language, Too

[ #35059 ]

It is said that "You can write FORTRAN in any language." I say that you can write (within limits) any language in any other language, although writing Common LISP in FORTRAN IV would probably involve first writing a Common LISP interpreter in FORTRAN IV.

As an example, let's take humble VB6. A common Perl idiom is to pass around a set of strings as one string concatenated by join() and de-concatenated by split(). Larry Wall borrowed join() and split() from Basic to start with, then enhanced split() to split on regexes (among other improvements). But non-regex join() and split() work just fine in VB6:

    tokenStr = join(passwd, ":")
    tokens = split(tokenStr, ":")

And quite a bit of the time, you don't need regex-based split() and join() ordinary split() and join() work just fine. (Maybe it is just me, but I haven't seen the join()/split() idiom much in native Basic code of whatever stripe.)

"But what about regexes?" you ask. In Win32 land (as I am), you can use the (essentially-built-in) Microsoft VBScript Regular Expressions 5.5. Though not as convenient as Perl's regexes, these VBScript 5.5 Regular Expressions are about as convenient as you can make class-based regexes:

    dim loincMatch as RegExp
    Set loincMatch = New RegExp
    loincMatch.Pattern = "^\d{1,5}-\d$"
    if loincMatch.Test(field(4)) Then

Everywhere (there is a C compiler) there are PCRE (Perl-Compatible Regular Expressions), which truly is about as close as you can get to Perl regexes outside of a Perl program (or plug-in).

Control structures from other languages can be used too (think of RATFOR for FORTRAN 66 or Switch in Perl 5). Fortunately, most modern languages have a fairly decent set of control structures.

This is part of the meaning of a Turing-complete language anything that can be expressed in one programming language can be expressed in another programming language, although (as I have noted before) you may end up writing an interpreter for language A in language B before you can start using A's language constructs when writing language B.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I knew about PCRE, but didn't know split, join
    came from BASIC.

    The way language designers 'port' other languages'
    features could be called 'incestuous.'

    But that's not really the right word.

    Evolutionarily speaking, it's not 'inheritance
    of acquired features' but 'inheritance of other
    monkeys' cool features.'
    • It’s not even inheritance. It’s more like bacterial conjugation.

      • I had to look that up. Here's an animation [] I think you're right. I wonder if perl6 will change that. The importance of BASIC to Larry comes out in the Onion State []
        • I think Perl 6 will change the game because it will be the first widely-deployed non-LISP-based language with many cool features now present only in academic languages. I suspect that we will see other languages start borrowing from Perl 6 because of these cool features.