Home > Backend Development > PHP Tutorial > What are the differences between PHP and Perl languages?

What are the differences between PHP and Perl languages?

伊谢尔伦
Release: 2016-11-21 14:58:30
Original
2103 people have browsed it

Similarities

Compiled scripting languages: Perl and PHP are both scripting languages. This means they don't have to execute the production native executable independently in advance.

Syntax: PHP's basic syntax is very close to Perl's, and both share many syntax features with C code like whitespace, statements terminated by semicolons, and curly braces to organize multiple statements into code blocks. A function call begins with the function name, followed by the actual parameters enclosed in parentheses and separated by commas.

$ sign variables: All variables in PHP look like Perl scalar variables: a name preceded by a $ sign ($).

No variables declared: Like the Perl language, you do not need to declare the type of a PHP variable before using it.

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-quoted strings much more often than single-quoted strings.

The difference

PHP is an HTML embedded language: Although you can use PHP to run arbitrary tasks from the command line, it usually requires connecting to a web server and being used to generate web pages. If you're used to writing CGI scripts in Perl, the main difference from PHP is that instead of explicitly printing a bunch of static HTML or heredoc statements, you can simply write chunks of PHP code outside of the HTML itself.

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

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

Specified function parameters: Function calls in PHP look a lot like calls in Perl subroutines. Function definitions in PHP, on the other hand, usually require some kind of formal argument list like C or Java. This is not the case in PERL.

Variable scope in Perl functions: The default scope of variables is global. This means that top-level variables are visible in subroutines. Often this leads to promiscuous use of global functions. In PHP, variables are local by default within the scope of the function definition.

No module system like this: there is no real difference in PHP between normal code files and code files used as import libraries.

Use keywords Break and continue instead of keywords next and last: PHP is more like C language, using keywords Break and continue instead of keywords next and last.

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

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

Regular Expressions: PHP has no built-in regular expression-specific syntax, but much of the same functionality is in its "Perl-compatible" regular expressions.


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template