What is the difference between PHP and Perl language?

Source: Internet
Author: User
Tags scalar
In the same place

Compilation scripting language: Both Perl and PHP are scripting languages. This means that they do not have to run their own production native executables in advance.

Syntax: PHP's basic syntax is very close to Perl, and both share a lot of syntax features like spaces, statements terminated by semicolons, and braces multiple statements organized into blocks of code with C code. function calls begin with the function name, followed by the actual arguments enclosed in parentheses and separated by commas.

$ symbol Variable: All variables in PHP look like Perl scalar variables: a name in front of a $ sign ($).

There are no declared variables: As with the Perl language, you do not need to declare a PHP variable before it is used.

Loosely typed variables: Like the Perl language, PHP variables have no intrinsic type other than the type of their current value. You can store numbers or strings in variables of the same type.

String and variable interpolation: PHP and Perl use double-quote strings more often than strings that use single quotes.

The difference

PHP is an HTML embedded language: Although you can use PHP to run any task from the command line, it usually needs to be connected to a Web server and used to generate Web pages. If you're used to writing CGI scripts in Perl, the main difference with PHP is that you no longer need to explicitly print a large number of static HTML or HEREDOC statements, but rather simply write PHP blocks of code outside of the HTML itself.

No @ or% variable: PHP has only one type of variable, which starts with a dollar sign ($). Languages of any data type can be stored in these variables, whether they are scalar or composite types.

Arrays and hashes: There is a data type called an array, like hashes and arrays played by the role in the Perl language.

Specified function arguments: function calls in PHP look much like called in Perl subroutines. In the function definition of PHP, and on the other hand, it is usually necessary to have some sort of formal parameter list, such as C or Java, that is not the case in PERL.

Variable scopes in Perl functions: The default range of variables is global. This means that the top-level variable is visible in the subroutine. Typically, this results in a mixed use of global functions. In PHP, variables are local by default in the scope of the function definition.

There is no such thing as a module system: There is no real difference between normal code files and code files used as import libraries in PHP.

Use keywords break and continue do not use keywords Next and last:php more like the C language, use the keyword break and continue to replace the keyword next and last.

No elsif: A small spelling difference: Perl's elsif is ElseIf in PHP.

More types of annotations: In addition to the Perl-style (#) Single-line comment, PHP provides a C-style multiline comment (/* comment */) and a Java-style single-line comment (//comment).

Regular Expressions: PHP does not have a built-in syntax for a specific hermetical expression, but most of the same functionality is in its "perl-compatible" regular expression.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.