Mombu the Php Forum sponsored links

Go Back   Mombu the Php Forum > Php > PHP equivalents of Perl
User Name
Password
REGISTER NOW! Mark Forums Read

sponsored links


Reply
 
1 25th March 05:43
jeff
External User
 
Posts: 1
Default PHP equivalents of Perl



Hello,

I'd like to port some perl code to PHP.

PHP looks a lot like perl and javascript to me, but there's a few
things I'm confused about, please f****ve the pseudo PHP syntax.

####
Perl lets you assign a "function" to an array, we call that a hash table
in perl.

So, can you do this in PHP?:

$y='Hello';

$my_custom['echo_foo']=function echoFoo($x){
return $x;
}

if($my_custom['echo_foo']){
echo $my_custom['echo_foo']($y);
}

####

Perl has CGI.pm where you can create form elements easily, for ex:

$popup=$query->popup_menu(-name=>'subsection',-default=>'some_default',-values=>'....);

Is there a library similar in PHP?

####
In Perl you can execute a function in a regular expression
substitution:, so that you can take the regex match and feed that to a
function, the return value from that function is then substituted in for
the match. How is this done in PHP?

####
How about a simple example of saving an uploaded file to the server?

###
Perl lets you make a reference to a variable, is there anything like
this in PHP?

###
What about error handling, perl is wonderful in this. How are errors
handled in PHP?

If there's a good tutorial on porting let me know, I've been
looking... Or just a good PHP tutorial. I'm still confused about scoping
in PHP...

Jeff
  Reply With Quote


  sponsored links


2 25th March 05:43
michael fesser
External User
 
Posts: 1
Default PHP equivalents of Perl



..oO(Jeff)


call_user_func() can be used to call functions whose names are stored in
variables.

See the function handling chapter in the PHP manual.

Many. Check PEAR or Google. I can't recommend a particular one, because
I use my own stuff.

Use preg_replace() with the /e modifier or preg_replace_callback().

See the PCRE chapter.

See the file upload chapter.

$foo = 42; // assignment
$bar = &$foo; // reference

See the references chapter.

See the error handling chapter.

Almost everything is described in the PHP manual. Also check out the
user contributed notes, they often contain valuable hints and examples.

Micha
  Reply With Quote
3 25th March 05:43
hendri kurniawan
External User
 
Posts: 1
Default PHP equivalents of Perl


You can also do this:
$my_custom['evhi_foo'] = create_function('$x', 'return $x;');

This is however not recommended when you create anonymous function
inside a loop, as it will eat your memory.

Some people will be against using such function, but it does give you
an alternative way of storing functions within a variable.

Hendri Kurniawan
  Reply With Quote
4 25th March 05:43
jeff
External User
 
Posts: 1
Default PHP equivalents of Perl


Thanks. I'll look into both methods.

Typically what I do is is leave hooks in my code (with the "hash
table") so that I can expand/alter functionality without altering the
base code. That lets me use the built in core functionality for
different projects and put all the customizations in a defaults file
which is customized to each. Perhaps PHP has a better way of doing this.

Learning...

Which of the PHP groups should I be posting to? Jeff
  Reply With Quote
5 25th March 05:43
erwin moller
External User
 
Posts: 1
Default PHP equivalents of Perl


Jeff schreef:

Hi,

comp.lang.php is the most active group.
Stick to that one.
Regards, Erwin Moller
  Reply With Quote
6 25th March 05:43
hendri kurniawan
External User
 
Posts: 1
Default PHP equivalents of Perl


Hi Jeff,

IMHO PHP is less "fussy" than PERL, but that's a matter of personal opinion.
I've also recently added hooks for a webapp that I'm working on.... I've
choosen to use "call_user_func",
as it suits the requirements just fine....

Like Erwin said, comp.lang.php is the most active group I've come across.

Hendri Kurniawan
  Reply With Quote
Reply


Thread Tools
Display Modes




Copyright © 2006 SmartyDevil.com - Dies Mies Jeschet Boenedoesef Douvema Enitemaus -
666