Hello folks! welcome back to a new section of our tutorial on PHP. In this tutorial guide, we are going to be studying about PHP for Perl Developers.
This tutorial is going to be focused on the similarities and differences between PHP and Perl. It will help Perl programmers to quickly understand PHP basics and avoid common mistakes.
This tutorial is going to be focused on the similarities and differences between PHP and Perl. It will help Perl programmers to quickly understand PHP basics and avoid common mistakes.
Similarities between PHP and Perl
- They are compiled scripting languages - Both PHP and Perl are scripting languages. This simply means that they are not used for production of standalone executables in advance of execution.
- Syntax - PHP's basic syntax is very close to that of Perl's, and they both share a lot of syntactic characteristic with C. Codes are Insensitive to whitespace. Statements are terminated by semicolons, & curly braces arranges many statements into just a single block. Function calls begins with the function name, and then followed by the actual arguments which are placed within parentheses and then separated by commas.
- Dollar-sign variable - All the variables in PHP resembles scalar variables in Perl: that is a Perl name with a dollar sign ($) in front of it.
- No variable declaration - As in Perl, you are not required to declare the type of a PHP variable before using it.
- Interpolation of strings and variables - PHP and Perl do additional interpretations of double quoted strings than single quoted strings.
- Loose variables typing - As in Perl, variables in PHP has no intrinsic type other than the value that they currently hold. Either number or string can be stored in same type of variable.
READ: PHP for C Developers
Differences between PHP and Perl
- PHP is HTML-Embedded - Although it is not possible to use PHP for arbitrary tasks by running the PHP from the command prompt, it is more typically connected to a web server and used to produce web pages. If you are used to writing CGI scripts in Perl, the major difference in PHP is that you no longer need to explicitly print large blocks of static Html using print or heredoc statements, instead you can simply just write the Html itself outside the PHP code block.
- Arrays vs hashes - PHP has a single data type called an array that plays both roles of hashes and array/but lists in Perl.
- The scoping of variables in Functions - In Perl language, the default scope of variable is global. This simply means that the top-level variables are visible inside subroutine. Often, this leads to random use of global across various fuctions. In PHP, the scope of variables within function definitions is local by default
- No @ or % variables - PHP has only one kind of variable which starts with a dollar ($) sign. Any of the datatypes in the language can be stored in such variable, be it scalar or compound.
- Specifying of arguments to functions - Function calls in PHP looks pretty much like subroutine calls in Perl. The function definitions in PHP, on the other hand, typically requires some kind of list of arguments like in C or Java which is not the case in Perl.
- No elsif - A minor difference in spelling; the PHP's elseif is Perl's elsif.
- Regular Expressions - PHP do not have a built-in syntax specific to Regexps, but has most of same functionality with Perl regular expression functions.
- No module system as such - In PHP language, there is no real difference between the normal code files and code files that's used as imported libraries.
- Break and continue instead of next and last - PHP uses break and continue instead of next and last statement.
- More kinds of comments - In addition to Perl style (#) single line comments, PHP provides C style multi-lines comments (/* */) and Java style single line comments (//).
Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about PHP Forms.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.