If you ever decide to create your JavaScript to Perl converter, here are a couple of things I learned:

If you need to work with a long string, replacing characters, inserting strings, splitting/joining strings, then in JavaScript it is a lot faster to convert the string into an array of characters and then work on the array elements one by one. The split() and join() functions are extremely fast in JavaScript, however if this code is converted into Perl, it becomes very slow! I've noticed that Perl code runs faster if you leave the string as a string and work on it by replacing characters using the vec() and substr() functions. Perl is better with strings than arrays. Having a big array in Perl just slows things down. In JavaScript, it's just the opposite!

Secondly, the % operator works quite differently in Perl than in JavaScript! Consider the following JavaScript code:

C = A % B;

This translates to the following Perl code:

$C = $A - int($A / $B) * $B;

So, this operator is tricky! It's easy to overlook this difference.


In reply to Re: A comparison of Perl vs. JavaScript -- a reference table. by harangzsolt33
in thread A comparison of Perl vs. JavaScript -- a reference table. by taint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.