Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Help with PHP-to-Perl CPAN bundle

by gunzip (Pilgrim)
on Sep 28, 2004 at 17:02 UTC ( [id://394681]=perlquestion: print w/replies, xml ) Need Help??

gunzip has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to compile a CPAN bundle which will provide a Perl equivalent of the standard PHP function library for use in converting PHP scripts to Perl and for presenting Perl as a ready-to-go alternative to PHP. The aim is to have everything at one's fingertips to counter the fud about PHP being easier to use due to its packaging.

I would assume much of PHP's feature set is available somewhere on CPAN but that's the problem. Unless you know CPAN very well it's difficult to find exactly what you're looking for. Hence the project. What isn't available on CPAN will need to be written from scratch.

As my knowledge of CPAN isn't that deep I'm looking for assistance from Perl monks. I think it will be a valuable tool for re-asserting Perl's relevance for smaller web projects where PHP has become the de facto choice in recent years. I'm also looking to use this in college evening classes where there isn't the option of going online to CPAN every time you need something. Such a bundle would also enable web developers to quickly install a feature-complete development environment on a laptop for offline use.

Main PHP function groups

Apache-specific | Array | Bzip2 | Calendar | Class/object | CURL | Character-Type | Date & Time | DOM XML | Error Handling & Logging | Filesystem | FTP | Function Handling | Gettext | HTTP | iconv | Image | IMAP,POP3,NNTP | Mail | Mathematical | Mcrypt | Mhash | Mimetype | Miscellaneous | Multibyte String | MySQL (< 4.1) | Improved MySQL (>= 4.1) | Network | OpenSSL | Output Control | Object Overloading | PDF | PostgreSQL | Pspell | Session Handling | SimpleXML | Standard PHP Library (PHP5) | SOAP | Stream | String | TCP Wrappers | Tidy | URL | Variable | XML Parser | XML-RPC | XSL | XSLT | Zlib

Replies are listed 'Best First'.
Re: Help with PHP-to-Perl CPAN bundle
by erikharrison (Deacon) on Sep 28, 2004 at 17:55 UTC

    Hrm. Embperl perhaps, though for small to middle sized sites, HTML::Template is preferable.

    PHP has mysql functions built in, so DBI and the mysql driver are a good pick. However, the DBI framework is again a little bit more involved, and is object oriented, so perhaps not the best pick for a PHP convert. Anyone know of a purely procedural equivalent, mysql only?

    Other than that, PHP has some HTML manipulating functionality, and that's about it. CGI.pm has the escapeHTML function, and HTML::Scrubber I believe should do the rest.

    The pretty much covers functionality that PHP posesses that Perl doesn't, but it doesn't cover that you don't have to import any of these things in PHP. You may consider creating a wrapper module to include this functionality, or even provide same name functionality for the Perl scripts. Then again, if you're teaching classes, then teaching the language and the modules is probably better than making them learn a throw off framework designed to imitate another language.

    There are some difference that you'll need to make PHP developers aware of, kind of a cheat sheet.

    • Ignore function prototypes in Perl, they don't work like you think they work. This is one of two features that I miss in Perl when coming back from PHP.
    • foreach my $alias (@array) creates an alias to the @array entry. Mutiple aliases in the loop aren't possible. (In PHP you can do for ($hash => $key, $value) {...} to do multiple aliases)
    • Arrays and Hashes are not the same data structure, and hashes do not preserve order.
    • Perl has a debugger! Rejoice!
    Cheers,
    Erik

    Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

      Forgive me, fellow monks, I have been touching up the documentation for the Advanced PHP Debugger (APD) recently after attending George Schlossnagle's profiling session at php|works 2004.

      There's also Xdebug, which Derick Rethans develops and maintains. It's used for the debugging support in Komodo, for one.

      One of the things I found at php|works is that the people who actually develop the language don't tend to have fanatical devotion to their language; instead, they look at other languages as tools, each of which might be more suited for a particular job than another, and each of which has something that they might learn from and adapt (or evolve) for their own language. Quite refreshing. I'm looking forward to YAPC 2005!

      Oh, another item for the cheat sheet: the & sigil means very different things in Perl and in PHP. You know what it does in Perl, but in PHP the & means "pass this by reference". You can prepend it to a variable when you pass it into a function, or assign it to another variable, or you can prepend it to the variable name in a prototype so that you always get the reference to the object being passed in.

      Embperl perhaps, though for small to middle sized sites, HTML::Template is preferable.

      I'm not really looking to favour any particular approach to Perl web development; rather to cover the major function groups within PHP:

      Apache-specific | Array | Bzip2 | Calendar | Class/object | CURL | Character-Type | Date & Time | DOM XML | Error Handling & Logging | Filesystem | FTP | Function Handling | Gettext | HTTP | iconv | Image | IMAP,POP3,NNTP | Mail | Mathematical | Mcrypt | Mhash | Mimetype | Miscellaneous | Multibyte String | MySQL (< 4.1) | Improved MySQL (>= 4.1) | Network | OpenSSL | Output Control | Object Overloading | PDF | PostgreSQL | Pspell | Session Handling | SimpleXML | Standard PHP Library (PHP5) | SOAP | Stream | String | TCP Wrappers | Tidy | URL | Variable | XML Parser | XML-RPC | XSL | XSLT | Zlib

      the DBI framework is again a little bit more involved, and is object oriented, so perhaps not the best pick for a PHP convert. Anyone know of a purely procedural equivalent, mysql only?

      interestingly, the new mysqli interface in php5 adds oo and is similar to DBI.

      perl -e"\$_=qq/nwdd\x7F^n\x7Flm{{llql0}qs\x14/;s/./chr(ord$&^30)/ge;print"

      foreach my $alias (@array) creates an alias to the @array entry. Mutiple aliases in the loop aren't possible. (In PHP you can do for ($hash => $key, $value) {...} to do multiple aliases)
      Unless I'm misunderstanding this (not knowing PHP), then what you are looking for here is each. eg:
      while (my ($key, $value) = each %hash ) { .. }
      Or am I way off the mark?

      C.

        $key, $value are copies of the values in the hash. The => operator can be used in PHP to create aliases to the elements, so changing $value is the same as changing $hash{$key} (to use Perlish syntax). So, in PHP:
        $array = (0,1,2,3,4,5); for ($array => $a, $b, $c) { $c = 'two'; } print ($array[2]) #Prints 'two'
        Cheers,
        Erik

        Light a man a fire, he's warm for a day. Catch a man on fire, and he's warm for the rest of his life. - Terry Pratchet

Re: Help with PHP-to-Perl CPAN bundle
by jacques (Priest) on Sep 28, 2004 at 17:13 UTC
    I am working on a similar PHP-to-Perl project. So maybe we could help each other. /msg me and let's talk.
Re: Help with PHP-to-Perl CPAN bundle
by CountZero (Bishop) on Sep 28, 2004 at 19:07 UTC
    Will all this work still be useful when PHP 5 hits the webservers? It is rumoured to be very close to Java, so much even that conspiracy theories about the link between SUN and ZEND abound.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

      The function subset listed above is based on the current documentation as of PHP 5.0.2

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://394681]
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-20 00:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found