Pages

Wednesday 18 July 2012

PHP & PERL

                    PHP and PERL similarities and differences
We all know about perl. Perl is a  Practical Extraction and Reporting Language.Perl was developed as a general-purpose Unix scripting language to make report processing easier Perl borrows features from other programming languages including C, shell scripting , AWK, and sed.The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary Unix tools,facilitating easy manipulation of text files.
We will know discuss similarities and differences of both one by one.
Similarities:-

1.Compiled scripting languages: Both Perl and PHP are scripting languages.This means that they are not   used  to produce native standalone executables in advance of execution.


2.Syntax: PHP's basic syntax is very close to Perl's, and both share a lot of syntactic features with C. Code is insensitive to whitespace, statements are terminated by semicolons, and curly braces organize multiple statements into a single block. Function calls start with the name of the function, followed by the actual arguments enclosed in parentheses and separated by commas.


3.Dollar-sign variables: All variables in PHP look like scalar variables in Perl: a name with a dollar sign ($) in front of it.


4.No declaration of variables: As in Perl, you don.t need to declare the type of a PHP variable before using it.


5.Loose typing of variables: As in Perl, variables in PHP have no intrinsic type other than the value they currently hold. You can store iether number or string in same type of variable.


6.Strings and variable interpolation: Both PHP and Perl do more interpretation of double-quoted strings ("string") than of singlequoted strings ('string').


Differences:


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.


1.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.


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


3.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.


4.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.


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


6.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.


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


8.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).


9.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.

No comments:

Post a Comment