PHP for PERL Programmers

This chapter will list some of the major similarities and differences between PHP and PERL. This helps PERL programmers understand PHP faster and avoid common errors.

This chapter will list some of the major similarities and differences between PHP and PERL. This helps PERL programmers understand PHP faster and avoid common errors.

Similarities between PHP and PERL

Compiled Scripting Language - Both Perl and PHP are Scripting languages.

Syntax - PHP's basic syntax is quite similar to Perl, and both share a lot of syntactic characteristics with C. Code is indistinguishable from whitespace, semicolons ending with semicolons, and curly braces Create multiple commands into a single block. Call the function starting with the function name, followed by the actual parameters enclosed in parentheses and separated by commas.

$ Symbol before the variable - All variables in PHP are quite similar to scalar variables in Perl: $ symbol before the variable name.

Don't declare variables - As in Perl, you don't need to declare the type of a PHP variable before using it.

Variable types are quite free - As in Perl, variables in PHP have no intrinsic type, nothing other than the value they keep present. You can store either the number or string in the same variable.

Interpolation and string - Both PHP and Perl perform more compilation of double-quoted strings ("strings") than single-quoted strings ('string').

Differences between PHP and PERL

PHP can be embedded in HTML - Although it is possible to use PHP for arbitrary tasks by running it command line itself, it is more specific than being connected to the Web Server and used to create web pages. If you used to write CGI scripts in Perl, the main difference in PHP is that you don't need to explicitly print the big code blocks of static HTML by using the print or heredoc commands and instead, you have Can write HTML outside the PHP code block.

No variable type @ or% - PHP has only one variable type, starting with a $. Any data type in this language can be stored in these variables.

Array vs Hash - PHP has a single data type called Array, which plays both Hash and Array roles in Perl.

Determining parameters for functions - Calling functions in PHP looks pretty much like calling subroutines in Perl. Function definitions in PHP need some formal parameters like in C or Java, unlike in Perl.

Variable scope in function - In Perl, the default scope for variables is global. That is, the top-level variables are visible inside the subroutine. This increases the messy use of global variables in functions. In PHP, the variable scope in the function definition, by default, is local.

No Module System - In PHP, there is no real distinction between regular file code and file code used as an Imported Library.

Break and continue orders instead of next and last - PHP are quite similar to C and use break and continue commands instead of next and last orders.

No elsif - The difference in spelling is: elsif in Perl is elseif in PHP.

More comment types - In addition to single-line comments like Perl-style (#), PHp provides multi-line comments C-style (/ * comment * /) and single-line comments Java-style (// comment).

Regular Expression - PHP does not have a specific syntax available for Regular Expressions, but has most of the same features as in the Perl Integrated Regular Expression Functions.

Follow tutorialspoint

Previous post: PHP for Programmer C

Next lesson: Date & Time in PHP

5 ★ | 1 Vote | 👨 311 Views
« PREV POST
NEXT POST »