Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

What is the difference between PHP & Perl?

user-image
Question ajoutée par Farah Maher , software developer , IT House Solutions
Date de publication: 2013/07/04
Osama Agha
par Osama Agha , Senior DevOps Engineer , Tabadul

  • PHP is HTML-embedded: Although it is possible to use PHP for arbitrary tasks by running it from the command line, it is more typically connected to a Web server and used for producing Web pages. If you are used to writing CGI scripts in Perl, the main difference in PHP is that you no longer need to explicitly print large blocks of static HTML using print or heredoc statements and instead can simply write the HTML itself outside of the PHP code block.
  • No @ or % variables: PHP has one only kind of variable, which starts with a dollar sign ($). Any of the datatypes in the language can be stored in such variables, whether scalar or compound.

  • Arrays versus hashes: PHP has a single datatype called an array that plays the role of both hashes and arrays/lists in Perl.

  • Specifying arguments to functions: Function calls in PHP look pretty much like subroutine calls in Perl. Function definitions in PHP, on the other hand, typically require some kind of list of formal arguments as in C or Java which is not the csse in PERL.

  • Variable scoping in functions: In Perl, the default scope for variables is global. This means that top-level variables are visible inside subroutines. Often, this leads to promiscuous use of globals across functions. In PHP, the scope of variables within function definitions is local by default.

  • No module system as such: In PHP there is no real distinction between normal code files and code files used as imported libraries.

  • Break and continue rather than next and last: PHP is more like C langauge and uses break and continue instead of next and last statement.

  • No elsif: A minor spelling difference: Perl's elsif is PHP's elseif.

  • More kinds of comments: In addition to Perl-style (#) single-line comments, PHP offers C-style multiline comments (/* comment */ ) and Java-style single-line comments (// comment).

  • Regular expressions: PHP does not have a built-in syntax specific to regular expressions, but has most of the same functionality in its "Perl-compatible" regular expression functions.

     

More Questions Like This