|
Posted by Bart the bear on 02/15/06 22:23
Mladen Gogala wrote:
> map { unlink($_) if -f $_; } glob("/mydir/*");
Speaking of this, is there any chance of references to functions in
PHP?
The "{ unlink($_) if -f $_; }" part of the code here is so called
"anonymous
subroutine" or "subroutine reference" which is sort of convenient if
you don't
want to clutter the namespace with unneeded function names. All you
need
to be able to implement your one-liner in PHP is an anonymous function
reference
to pass to array_walk, which is identical to Perl's "map".
Also, Perl has qr() construct which compiles regular expressions and
makes
things significantly faster. Is there any flag to compile regular
expression in
prreg_match? The only documented flag here is to capture offset. If I
need to
go through multiple lines in a loop, will PHP compile the regular
expression?
The situation I have in mind is something like this:
while ( $line=fread($file,128)) {
if preg_match("/$regexp/",$line,$found)....
}
As you can see, I'm a beginner with PHP. I have 5 years or so
experience
with Perl.
Navigation:
[Reply to this message]
|