Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Let's start by examining just one snippet of your Javascript code:

c = c.charCodeAt(0); c++; c = c.toString(); temp = c; c = String.fromCharCode(temp); line += c;
I hadn't written any Javascript until just now, but it seems to me (and correct me if I'm wrong) that the above code could be equivalently expressed in one line as:
line += String.fromCharCode(c.charCodeAt(0)+1);
which is equivalent to the Perl code:
$line .= chr(ord($c)+1);
assuming that $c contains just one character, as I believe it does from reading your code. Note that Perl uses a dot rather than a plus sign to concatenate strings. The Perl ord function returns the ord value (0-255) of a character while the Perl chr function does the reverse.

Given your lack of Perl experience, rather than attempting to convert the whole script all at once, I suggest you start by writing a number of very short Perl test programs, liberally sprinkled with print statements, so you can see what is going on. That should slowly build your confidence without overwhelming you. For example, you could start by running this little test program:

use strict; use warnings; my $line = "hello"; my $c = "A"; print "1. line='$line' c='$c'\n"; $line .= chr(ord($c)+1); print "2. line='$line' c='$c'\n";
which should print:
1. line='hello' c='A' 2. line='helloB' c='A'
Always start your Perl scripts with "use strict" and "use warnings" as shown above. Doing that will catch a lot of errors for you.

As for learning Perl, take a look at and Perl Tutorial Hub. Also, be sure to refer to the Perl online documentation. Good luck!

In reply to Re: Javascript to Perl = fail by eyepopslikeamosquito
in thread Javascript to Perl = fail by Anonymous Monk

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and nobody stirs...

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (9)
    As of 2018-06-22 12:01 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (124 votes). Check out past polls.