PHP vs. PERL

Source: Internet
Author: User
Author: anonymous Source: Webmaster Bar Date: 2006-01-10 Hits: 48 font: Big Small input: [Master8]
This article is http://tnx.nl/php-if you want to copy him, please keep this link.

Translation: Shiningray @ Nirvana Studio
Directory

* Parameters and return values are extremely contradictory
* PHP uses different functions for case insensitive operations
* Inconsistent function naming methods for PHP
* PHP has no lexical scope
* There are too many functions in the main name space of PHP
* PHP lacks abstraction to make timtowtdi go to bad extremes
* More Information

Parameters and return values are extremely contradictory

To demonstrate this problem, here is a list of functions that match the user-defined content: (maybe even those who use PHP will use this document, just to see which function to use: P)
Match substitution using case insensitive returns the number array parameter returns the match s/m/x flag offset ( -1= end)
Ereg ereg No no array no 0
Ereg_replace Ereg String No all no no no no 0
Eregi ereg No no array no 0
Eregi_replace Ereg String No all no no no no 0
Mb_ereg ereg[1] No no array no 0
Mb_ereg_replace ereg[1] string/Expression No all no no no 0
Mb_eregi ereg[1] No no array no 0
Mb_eregi_replace Ereg[1] String No all no no no no 0
Preg_match Preg[2] can be a no array has 0
Preg_match_all preg all available no arrays have 0
Preg_replace preg string/expression can be none/All is no 0
Str_replace STR string No all is number no 0
Str_ireplace STR string is all numbers no 0
STRSTR, STRCHR str No one no substring no 0
Stristr STR is a no substring no 0
STRRCHR STR No no substring no-1
Strpos STR No one no index n
Stripos STR is a no index no n
Strrpos Char[3] No one no index n
Strripos STR is a no index no-1
Mb_strpos Str[1] No one no index n
Mb_strrpos Str[1] No one no index no-1

This problem still exists in other function groups, not just the matching part.

(In Perl, all of these features can be done with four simple operators.) )

[1] for processing multibyte characters
[2] PCRE regex: The so-called "Perl compatible" regular expression.
[3] In PHP5 is also the string str
PHP uses different functions for case insensitive operations

(This could be a two-part debate.) Some people think that providing a different function is better, even if it means remembering many nouns again.

In Perl, you can use two LC () or/I flags, and PHP usually provides a case-sensitive variable. Also, the names of the functions of those versions that are case insensitive are not named in the same way.
Perl: $foo CMP $bar LC $FOO CMP LC $bar
PHP:STRCMP ($foo, $bar) strcasecmp ($foo, $bar)

Perl:index ($foo, $bar) index (LC $foo, LC $bar)
Php:strpos ($foo, $bar) Stripos ($foo, $bar)

Perl: $foo =~ s/foo/bar/$foo =~ s/foo/bar/i
PHP: $foo = Str_replace ("foo", "Bar", $foo) $foo = Str_ireplace (...)
PHP: $foo = ereg_replace ("foo", "Bar", $foo) $foo = eregi_replace (...)
Inconsistencies in the way PHP functions are named

* The case insensitive function has an "I" or a "box" in a different position in the function name.
* No representation of the rules are underlined and not underlined:

Underline no underline:

Stream_get_line ReadLine
Disk_free_space Diskfreespace
Is_object Isset
Mcal_day_of_week Jddayofweek
Set_error_handler setlocale
Snmp_get_quick_print Snmpget
Get_browser getallheaders
Base64_encode UrlEncode
Image_type_to_mime_type Imagetypes
Msql_num_fields Mysql_numfields
Php_uname phpversion
Strip_tags stripslashes
Bind_textdomain_codeset Bindtextdomain
CAL_TO_JD GREGORIANTOJD
Str_rot13 Strpos

The core function name of Perl does not contain an underscore.
* PHP has unlink, link and rename and system calls consistent, but the touch system call is utime, not touch.
* At the same time you cannot determine the order of the words:
O Object verb: base64_decode, iptcparse, Str_shuffle, Var_dump
O Verb object: create_function, recode_string

The core function of Perl is the dbm* function of the "verb object" structure except the substitution. (Note that the sys inside is a prefix, not an object.) Both flock and Lstat are named according to the system call. shm* and msg* are library function calls)
* "to" or "2"?

Ascii2ebcdic, Bin2Hex, Deg2rad, Ip2long, Cal_to_jd (jdto*, *tojd), Strtolower, Strtotime,

PHP has no lexical scope

Perl has lexical scope and dynamic range. PHP is not.

For explanations of why the lexical scope is important, you can refer to coping with scoping.
PHP Perl
Hyper-Global (Superglobal) there are [1]
Global there are
function Local there are
Lexical domain (block local) None
Dynamic Domain None available

[1] Perl has some variables that are always in the main:: namespace. These are similar to PHP's hyper-global variables.
[2] A lexical variable is used in a block of a sub-procedure, and can be used as a local variable of a function.
There are too many functions in the main name space of PHP

(using a core library that compiles the available extensions in all core bundles, we used the version released in November 2003)

Number of main functions in PHP: 3079 [1]
Number of Perl main functions: 206 [2]

Median PHP function name length: 13
Average PHP function name length: 13.67
Median Perl function name length: 6
Average Perl function name length: 6.22

Note that some Perl functions have a short, equivalent syntax:

readpipe ("ls-l") ==> ' ls-l '
Glob ("*.txt") ==> <*.txt>
ReadLine ($FH) ==> < $fh >
Quotemeta ($foo) ==> "Q$foo"
Lcfirst ($foo) ==> "L$foo" (LC is L)
Ucfirst ($foo) ==> "U$foo" (UC is U)

[1] Source: PHP Quick Reference
[2] Source: Perldoc Perlfunc
PHP lacks abstraction to make timtowtdi* go to bad extremes

* (There is more Than one ways to do it, there is not a way of doing it)

Why does PHP have 3,079 functions but Perl has only 206? In PHP, there are often several very similar functions. In Perl, you need to understand and remember a lot less.

Another important factor is the use of modules, especially the DBI module?? It is used to provide database support instead of stuffing many features into the kernel, which takes up space and is seldom used.

(The infrequently used modules are not counted (so php pear and perl io::file are excluded). If the core does not provide similar functionality, then these modules will also be counted inside. For simplicity, the internal working style will be ignored. )

*

Escape:

O

PHP: (14)
Dbx_escape_string, Escapeshellarg, Escapeshellcmd, Pg_escape_bytea,
Pg_escape_string, Pg_unescape_bytea, Addslashes, Addcslashes, Preg_quote,
Quotemeta, mysql_escape_string, mysql_real_escape_string,
Mysqli_real_escape_string, sqlite_escape_string

O

Perl: (2) [1]
Quotemeta, $DBH->quote

*

Sort:

O

PHP: (16)
Sort, Arsort, Asort, Krsort, Ksort, Natsort, Natcasesort, Rsort, Usort,
Array_multisort, Uasort, Uksort, Dbx_sort, Imap_sort, Ldap_sort, Yaz_sort

O

Perl: (1)
Sort

*

Traversing the list:

O

PHP: (10)
Array_filter, Preg_grep, Array_search, Array_unique, In_array, Array_map,
Array_walk, Array_count_values, Array_change_key_case, array_sum

O

Perl: (2)
Map, grep

*

Segmentation:

O

PHP: (8)
Split, explode, Strtok, Spliti, Chunk_split, Mb_split, Preg_split,
Str_split

O

Perl: (1)
Split

*

The:

O

String:

+

PHP: (11)
Strstr, STRCHR, Stristr, Strpos, STRRCHR, Stripos, Mb_strpos,
Mb_strrpos, Strrpos, Strripos, substr

+

Perl: (3)
Index, Rindex, substr

O

Regular Expressions:

+

PHP: (6)
Ereg, Eregi, Mb_ereg, Mb_eregi, Preg_match, Preg_match_all

+

Perl: (1)
m//

*

Replace the matching section:

* PHP: (12)
Ereg_replace, Eregi_replace, Mb_ereg_replace, Mb_eregi_replace,
Preg_replace, Str_ireplace, Str_replace, LTrim, RTrim, trim, nl2br

* Perl: (1)
s///

*

Connect to the database:

O

PHP: (17 or more)
Dbx_connect, Fbsql_connect, Ibase_connect, Msql_connect, Msql_pconnect,
Mssql_connect, Mysql_connect, Odbc_connect, Pg_connect, Pg_pconnect,
Sesam_connect, Ifx_pconnect, Ifx_connect, Sqlite_open, Sqlite_popen,
Mysqli_connect, Mysqli_pconnect

O

Perl: (2)
Dbi->connect, dbi->connect_cached

*

Open (file, process, etc.):

O

PHP: (5)
Dio_open, fopen, Proc_open, Popen, gzopen[2]

O

Perl: (2)
Open, Sysopen

*

Read/Receive:

O

PHP: (12)
Dio_read, Fread, gzread[2], Socket_read, SOCKET_RECV, Socket_recvfrom,
Socket_recvmsg, ReadLine, fgetc, fgets, stream_get_line, file

O

Perl: (5)
Read, ReadLine, Sysread, recv, getc

*

Print/Output/write:

O

PHP: (14)
Print, Echo, printf, fprintf, vprintf, Dio_write, fwrite, fputs,
Gzwrite[2], Socket_send, socket_sendmsg, Socket_sendto, Socket_write,
Socket_writev

O

Perl: (5)
Print, printf, syswrite, send, write

*

Shut down:

O

PHP: (7)
Closelog, Dio_close, Fclose, gzclose[2], Pclose, Socket_close,
Proc_close

O

Perl: (1)
Close

*

Common/tools:

O

Php:
Array_combine, Array_fill, Array_flip, Array_merge, list, range, count,
Create_function, Strtr, pow, putenv, getenv, Getmygid, Getmypid, Getmyuid

O

Perl:
Use syntax or magic variables

[1] Explicit escaping is often not required because of the system's list syntax and the placeholder for DBI.
[2] In Perl, it is handled by the Perlio layer.
More information

* Re^2:is Perl A good career move? by Juerd, 2005
o There is still no name space
o No closures, not even anonymous functions
o No Good HTML parser
o No simple MIME build tool
o No good www library
o No CPAN
o No arrays
o No use of logical operators
* Yaywoo! By Dave Brown, 2004
o Use System () to avoid (unsafe) shells
o Xy-problem
o A lot of different programs, however, a lot of just do a variant of the same thing
o the second parameter and return value are meaningless
o poor spelling of function names
* Why PHP sucks by Edwin Martin, 2004, Chinese translation Why PHP is unpleasant (for large systems) by Shiningray
o Poor recursive support
o PHP is not thread-safe
o PHP is not sound for business reasons
O No namespaces
o Non-standard date formatting characters
o Confusion of the license
o Inconsistent function naming conventions
O Magic Quotes Hell
* Perl vs. Php-octo "s subjektiver Vergleich by Florian Forster, 2003 (German)
o Perl is much faster than PHP
o Perl richer than PHP
o Perl has better documentation than PHP
o PHP lacks modularity support
o PHP Here-docs has no use for Windows users
O PHP lacks a consistent database API
o PHP Cache database query results are dangerous
o Graphics, PHP is actually limited to GD
* I hate PHP by Keith Devens, 2003
o idiot?? Reference pass is not recommended when calling
* Experiences of Using PHP in Large Websites by Aaron Crane, 2002
o PHP is a recommended combination of performance and business logic
o No namespaces cause a lot of problems
o PHP.ini's global configuration
o Excessive simplification leads to additional complexity
* PHP annoyances by Neil de Carteret, 2002
o no real references or pointers
o The concept of no namespace
O No Component
O wanted to be Perl, but in fact didn't want to become Perl.
o No standard DB interface
o All PHP communities are for non-programmers
O Chained method calls are not supported (now no longer--tnx.nl)
o There is no global variable unless by importing
o register_globals and $_request are distressing.
The O arrays are all Hassi
o PEAR is not CPAN
o Arrays cannot replace interpolated values with strings (such as $a=array (); $b = "$a"; is wrong)
o There is no function like "use strict" to verify variable names
* Php:a Love and hate relationship by Ivan Ristic, 2002
O Community makes me uneasy
O knowledgeable people are few and far between.
O Zend published articles also recommend unsafe practices
* My List of PHP shortcomings by Nathan Torkington, 2001
O No namespaces
o All functions are global
o No real references
o No real data structure (not now--tnx.nl)
o No anonymous function

Reference

EFnet #php: 19:45 <+Dragnslcr> comparing PHP to Perl are like comparing pears to newspapers

Perl monks:php-it "s" Training wheels without the bike "--Randal L. Schwartz

(:::
  • 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.