Comparison of the top three scripting languages

The scripting languages in this table were carefully chosen since they are the three scripting languages most in demand by employers, and they are all modern, dedicated scripting languages.
(Reference: sl_popularity.htm)

Language comparison

attribute scripting language
general name    
JavaScript
Perl
PHP
" name meaning       Practical Extraction
and Report Language
PHP Hypertext Preprocessor
" interpreted?     yes yes yes
  side client-side   Client-side JavaScript (default) no no
"   server-side   Server-side JavaScript (rare) yes yes
" price     free free free
" browsers
on which
included
    all (none) (none)
" file extension     .js .pl .php
" case sensitive? variables   yes yes yes
" " nonvariables       no
  embedding
in HTML
short form   <script type="text/javascript"> ... </script> (none) <? ... ?>
  " long form   <script language="Javascript" type="text/javascript"> ... </script> #!/usr/local/bin/perl <?php ... ?>
  comments C++ style   // comments go here (none) // comments go here
  " Unix style   (none) # comments go here # comments go here
  " C style   /* comments go here */ (none) /* comments go here */
  escape
sequences
escaping
character
  \ \ \
  " backspace   \b \b (none)
  " form feed   \f \f (none)
  " newline   \n \n \n
  " carriage
return
  \r \r \r
  " horizontal tab   \t \t \t
  " vertical tab   (none) \v \v
  " single quote   \' \' \'
  " double quote   \" \" \"
  " backslash   \\ \\ \\
  " dollar sign   (none) (none) \$
  formatting
characters?
    no yes no
  line
terminator
required?
    no yes yes
  line
terminator
    ; ; ;
standard
I/O
print/write 1 string   document.write("Hello world"); print "Hello world."; print "Hello world.";
" " 2 strings   document.write("Hello " + "world");   print "Hello " . "world.";
" " number   document.write(3);   print 3;
" " variable   document.write(y); print "$y"; print "$y";
datatypes declare
constants
    const PI = 3.14159; use constant PI => 3.14159; define("PI", 3.14159);
" type
casting
array       (array)
" " boolean       (boolean)
" " integer       (integer)
" " object       (object)
" " real       (real)
" " string       (string)
" variable prefix scalars   scalarname $scalarname $scalarname
" " arrays   arrayname @arrayname $arrayname
" " hashes   hashname %hashname $hashname
  string delimiters     "stringhere" "stringhere"
'stringhere'
"stringhere"
'stringhere'
operators arithmetic
operators
addition   + + +
" " subtraction   - - -
" " multiplication   * * *
" " division   / / /
" " exponen-
tiation
  (none) ** (none)
" " modulus   % % %
" concat-
enation
    + . .
" assignment     = = =
" shortcut
assignment
operators
increment   += += +=
" " decrement   -= -= -=
" " multiplication   *= *= *=
" " division   /= /= /=
" " modulus   %= %= %=
" " exponen-
tiation
  (none) **= (none)
" " concat-
enation
  += .= .=
" logical
operators
and   && && &&
" " or   || || ||
" " exclusive
or
  (none) (none) XOR
" " not   ! ! !
" equality
operators
equality   == == ==
" " equivalence   ===   ===
" " not equals   != != !=
" comparison
operators
less than   < < <
" " greater than   > > >
" " less than
or equal
  <= <= <=
" " greater than
or equal
  >= >= >=
" " ternery   (b == 5) ? a="true" : a="false"; ($b == 5) ? $a="True" : $a="False"; ($b == 5) ? $a="true" : $a="false";
  bitwise
operators
and   & & &
  " or   | | |
  " exclusive
or
  ^ ^ ^
  " not   ~ ~ ~
  " shift left   << << <<
  " shift right   >> >> >>
  " zero-fill
shift right
  >>>   (none)
data
structures
arrays first
need to be
created?
    yes no no
" array
assignment
individual   names[0] = "Peter";
names[1] = "Paul";
$names[0] = "Peter";
$names[1] = "Paul";
$names[0] = "Peter";
$names[1] = "Paul";
" " multiple     @names = ("Peter", "Paul"); $names = array("Peter", "Paul");
" class
creation
    function Staff(...)
{ ... }
struct Staff =>
{ ... };
class Staff
{ ... }
" class
instantiation
    employee = new Staff(); $employee = new Staff(); $employee = new Staff();
" field
assignment
    employee.name = "Mary"; $employee->name("Mary"); $employee->name = "Mary";
control
structures
conditional
statements
if blocked if (expression)
{ ... }
if (expression)
{ ... }
if (expression)
{ ... }
" " " un-
blocked
    if (expression)
$y = 0;
" " else blocked if (expression)
{ ... }
else
{ ... }
if (expression)
{ ... }
else
{ ... }
if (expression)
{ ... }
else
{ ... }
" " " un-
blocked
    if (expression)
$y = 1;
else
$y = 0;
" " else if blocked if (expression)
{ ... }
else if (expression)
{ ... }
else
{ ... }
if (expression)
{ ... }
elsif (expression)
{ ... }
else
{ ... }
if (expression)
{ ... }
elseif (expression)
{ ... }
else
{ ... }
" " " un-
blocked
    if (expression)
$y = 2;
elseif (expression)
$y = 1;
else
$y = 0;
" " switch   switch(varname)
{
case value1:
codeblock1
break;
case value2:
codeblock2
break;
...
default:
codeblockn;
}
(none) switch($varname)
{
case value1:
codeblock1
break;
case value2:
codeblock2
break;
...
default:
codeblockn;
}
" loops for   for ($i=1; $i<=10; $i++)
{ ... }
for ($i=1; $i<=10; $i++)
{ ... }
for ($i=1; $i<=10; $i++)
{ ... }
" " for each /
for in
  for (varname in arrname)
{ ... }
foreach (@arrname)
{ ... }
foreach $varname (@arrname)
{ ... }
foreach (arrexpr as $value)
{ ... }
foreach (arrexpr as $key => $value)
{ ... }
" " while   while (expression)
{ ... }
while (expression)
{ ... }
while (expression)
{ ... }
" " do while   do
{ ... }
while (expression);
do
{ ... }
while (expression);
do
{ ... }
while (expression);
" break     break; last; break;
" continue     continue; next; continue;
" functions no
returned
value,
argument
list
  function functionname()
{ ... }
sub functionname()
{ ... }
function functionname()
{ ... }
" " no
returned
value,
no argument
list
  (none) sub functionname
{ ... }
(none)
" " returned
value,
argument
list
  function functionname()
{
...
return value;
}
sub functionname()
{
...
return value;
}
function functionname()
{
...
return $value;
}
" " returned
value,
no argument
list
  (none) sub functionname
{
...
return value;
}
(none)
" " random
number
  $rn = Math.random(); $rn = rand($ul); srand ((double) microtime( )*1000000);
$rn = rand($ll, $ul);
" regular
expressions
POSIX
style
  no no yes
" " Perl-
style
  yes yes yes
file I/O open to read   (none) open($fh, "books.txt"); $fh = fopen("books.txt", "r");
" " to append   (none) open($fh, ">>books.txt"); $fh = fopen("books.txt", "a");
" " to overwrite   (none) open($fh, ">books.txt"); $fh = fopen("books.txt", "w");
" read       @userdata = $fh; $userdata = fread($fh, 1024);
" write       print $fh "$article"; fwrite($fh, $article);
" close       close($fh); fclose($fh);

References

Scripting languages in general

http://www.lurklurk.org/rosetta.html
http://www.5starsupport.com/tutorial/programming.htm

JavaScript

Negrino, Tom, and Dori Smith. 2004. JavaScript for the World Wide Web, Fifth Edition. Berkeley, CA: Peachpit Press
http://developer.mozilla.org/en/docs/Introduction_to_Object-Oriented_JavaScript
http://dickbaldwin.com/javascript/Java2115.htm#Assignment%20Operators
http://homepage.ntlworld.com/kayseycarvey/arrays.html
http://javascript.programmershelp.co.uk/specialchar.php
http://www.c-point.com/javascript_tutorial/jsgrpComparison.htm
http://www.educationonlineforcomputers.com/blogs/Free_Web_Development_Training_Tutorial_Resources.php
http://www.eecs.umich.edu/~bartlett/jsops.html
http://www.fullposter.com/snippets.php?snippet=99
http://www.guistuff.com/javascript/js_arrays_a1.html
http://www.hscripts.com/tutorials/javascript/ternary.php
http://www.pageresource.com/jscript/jarray2.htm
http://www.w3schools.com/js/default.asp
http://www.webreference.com/js/column26/stricteq.html
http://www.web-source.net/javascript_tutorial.htm
http://www.mediacollege.com/internet/javascript/basic/document-write.html
http://www.quirksmode.org/js/strings.html
http://www.webdevelopersnotes.com/tutorials/javascript/generating_random_numbers_javascript.php3
http://www.webreference.com/js/tips/001031.html

Perl

Brown, Martin C. 1999. Perl Programmer's Reference. Berkeley, California: Osborne/McGraw-Hill
http://affy.blogspot.com/p5be/ch04.htm
http://board.ringsworld.com/post-73.html
http://books.google.com/books?id=ezqe1hh91q4C&pg=PA337&lpg=PA337&dq=perl+class+struct&source=web&ots=juzAvy9VW-&sig=F0zOczTG_VCIU6A6y2fRkBahmu8#PPA336,M1
http://books.google.com/books?id=trejcrrdSwAC&pg=PA35&lpg=PA35&dq=perl+%22shortcut+assignment+operators%22&source=web&ots=ube3U06tgN&sig=l7oE19ezYYZaRfZt8vRkYhMiC7Y#PPA32,M1
http://cog.cognitivity.com/perl6/var.html
http://en.wikibooks.org/wiki/Perl_Programming/Array_Variables
http://perl.about.com/od/perltutorials/a/perlcomparison_2.htm
http://safari.oreilly.com/9780470048399/ch02lev1sec10
http://www.codeproject.com/KB/perl/camel_poop.aspx
http://www.comp.leeds.ac.uk/Perl/start.html
http://www.gnulamp.com/perlifelse.html
http://www.gnulamp.com/perlloop.html
http://www.informit.com/articles/article.aspx?p=29028&seqNum=4
http://www.itworld.com/nl/perl/09272001/
http://www.ngbdigital.com/perl_escape.html
http://www.perl.com/doc/manual/html/pod/perlre.html
http://www.rocketaware.com/perl/perlop/Equality_Operators.htm
http://www.tizag.com/perlT/perloperators.php
http://www.tizag.com/perlT/perlsyntax.php
http://www.tutorialspoint.com/perl/perl_scalars.htm
http://www.tutorialspoint.com/perl/perl_arrays.htm
http://www.xav.com/perl/lib/Class/Struct.html
http://www.cs.cf.ac.uk/Dave/PERL/node36.html
http://perl.tribe.net/thread/6375bc79-0e39-43ed-861d-5b12cfc0f67f
http://www.tizag.com/perlT/perlfileopen.php
http://www.comp.leeds.ac.uk/Perl/filehandling.html
http://perldoc.perl.org/functions/open.html
http://www.pageresource.com/cgirec/ptut14.htm
http://www.troubleshooters.com/codecorn/littperl/perlfile.htm

PHP

Gilmore, W. Jason. 2006. Beginning PHP and MySQL 5: From Novice to Professional, Second Edition. Berkeley, CA: Apress.
http://www.cis.upenn.edu/~matuszek/cit597-2004/Lectures/43-php.ppt
http://en.wikibooks.org/wiki/Programming:PHP/basics
http://www.phpbuilder.com/annotate/message.php3?id=1015491
http://www.htmlite.com/php012.php
http://www.alt-php-faq.org/local/28/

Language comparison

http://mavweb.net/javascript_and_vbscript_operators.asp
http://the-welters.com/professional/cgiclass/content_compared.html
http://en.wikipedia.org/wiki/Concatenation


Created: February 8, 2008
Updated: March 2, 2008