Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Help with PHP-to-Perl CPAN bundle

by erikharrison (Deacon)
on Sep 28, 2004 at 17:55 UTC ( #394698=note: print w/ replies, xml ) Need Help??


in reply to Help with PHP-to-Perl CPAN bundle

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


Comment on Re: Help with PHP-to-Perl CPAN bundle
Re^2: Help with PHP-to-Perl CPAN bundle
by gunzip (Monk) on Sep 28, 2004 at 18:56 UTC

    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

PHP has a couple of debuggers
by dazzle (Sexton) on Sep 28, 2004 at 21:32 UTC
    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.

Re^2: Help with PHP-to-Perl CPAN bundle
by pizza_milkshake (Monk) on Sep 29, 2004 at 02:28 UTC
    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"

Re^2: Help with PHP-to-Perl CPAN bundle
by castaway (Parson) on Sep 29, 2004 at 07:03 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://394698]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2014-07-29 11:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (215 votes), past polls