in reply to A comparison of Perl vs. JavaScript -- a reference table.

I'm coming from the other direction. I learned JavaScript first, and then Perl. Actually, the very first language I learned was BASIC, but it's amazing how many commonalities these languages share. Perl is a bit more like BASIC in the way it treats strings. You can do something like this : MID$(A$, 8, 1) = "A" in BASIC, which is the same as vec($A, 8, 8) = 65; in Perl. However, you can't do this in JavaScript. To achieve it anyway, you have to split the original string into two parts and add them together with the new "A" in the middle. This requires more memory, of course.

In Perl, you can access the command line through the @ARGV array. In BASIC, you can do it from COMMAND$ and there's a way to do it in JavaScript as well, but it varies depending on the application. For example in a HTA program, you would do it like this:

<HTA:APPLICATION ID="objTestHTA" ...>
</HEAD>

<SCRIPT>

alert( objTestHTA.commandLine );

</SCRIPT>

If you happen to write JavaScript for Node.js environment, then you'd use an array called process.argv to access the commandline arguments...

  • Comment on Re: A comparison of Perl vs. JavaScript -- a reference table.

Replies are listed 'Best First'.
Re^2: A comparison of Perl vs. JavaScript -- a reference table.
by LanX (Sage) on Dec 15, 2020 at 03:56 UTC
    Perl was the scripting language back then, and Brendan Eich admitted once that he was strongly influenced by Perl (that interview is hard to find now). This influence is more than obvious if you look at the Array methods.

    The story goes (IIRC):

    He was initially hired to write a Scheme like dialect. Many applications had embedded Lisp engines, like Emacs, AutoCad, Gimp,...

    But Netscape made a deal with Sun, and he was told to design something that looks syntactically like Java.

    As you mentioned , are strings one important difference, because they are immutable in JS, while in Perl they are a piece of memory at your free disposal.

    The lack of pure hashes is (or was?) a big problem in JS.

    There are some other issues, but for me is 90% of JS just a mini Perl with Java syntax.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      I heard him tell the story at CurryOn 2015 in Prague. IIRC, he was not only hired to write a Scheme like dialect, but he actually wrote it that way. When he was almost done like a week before the contract end, they asked him to change the syntax to be more Java-like.

      map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
        Did he mention Perl?

        I'm also asking because Perl lacks Lisp'ish macros - pretty much like JS does.

        OTOH is his regex syntax based on Perl 4, so he probably didn't know Perl 5 and features like private vars, anonymous subs and closures, are just a Co evolution.

        ( not sure if typecasting of primitive types is Lisp'ish, elisp is no good role model)

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery