You are here: Re: php and regex (why no =~ like perl)? « PHP Programming Language « IT news, forums, messages
Re: php and regex (why no =~ like perl)?

Posted by Mladen Gogala on 10/17/08 11:20

On Mon, 04 Jul 2005 09:33:56 -0700, el_roachmeister wrote:

> The problem is the functional syntax i.e preg_match takes up alot more
> space than a simple =~ . I write web-based software and my code is full
> of regexs so the =~ saves a lot of space.

Yes, the space argument stands. Most of the modern editors, however,
are not limited by the line size of 80 characters, so you can create
nice looking programs that will take a little more space.
On the other hand, Perl grammar is very complex and full of idioms
which are unintelligible to the non-consecrated humans. One
such example is this:

$a ||= 'Value';

Translated into PHP, the above expression would be written like this:

if (!defined($a)) { $a='Value'; }

I agree that Perl version is much shorter but is also much less
readable and harder to master. It means that it takes much longer
to learn the language. Also, variables like $_,@_,$! and $~ are much
harder to learn. They're also crucial and you cannot use the language
if you don't know what this means:

while (<>) {
chomp;
print "Line:$_\n" if /^\d+\s{2,}/;
}

All of that makes Perl much harder to learn then PHP. The philosophy of
PHP is similar to the philosophy of the C language: let's make the
language as simple as possible so that people can learn it quickly.
That is why PHP became so popular. The object model of PHP is much
more natural and much easier then the Perl equivalent. Have you ever
tried @ISA array?

>
> Also there seems to be several functions to do regex in php. I am not
> sure which will even be supported in future releases?

PCRE library is supported by almost anything. I have no reason to believe
that they will go away in near future.

--
http://www.mgogala.com

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация