Re: Coverting perl to php



On Sep 4, 6:34 am, Curtis <dye...@xxxxxxxxx> wrote:
Jeff wrote:
Michael Vilain wrote:
In article
<0a67ee87-6cd0-47a5-9325-11b40244e...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
 Bill H <b...@xxxxxxxxx> wrote:

Hi

I have some perl code that lets me request different things, images,
audio, etc and it will output the correct mime type header and
"stream" the file to a browser (instead of a hard link to the image
itself). I am bout ready to convert it to php but wonder if there are
already built in commands to do this. If so can someone give me a
pointer or 2 where to look in the manual (I am not that good with
search engines).

TYI

Bill H

Most language translation packages going from one language to another
do about as well as Babylfish in parsing german to english.  They sort
of work, but there's nothing to match a good perl person porting their
code to php.  Lots of Perl's function and features comes from CPAN
modules others have written and supported.  Perl's CPAN has _years_ on
php's PEAR.  I'm speculating that the perl code you're going to port
will use lots of CPAN code which you'll have to port as well.

I agree.

  I've just been rewriting most of my utilities from perl to php. I did
a complete rewrite because, I'm a better programmer than when I first
wrote the code and I like the way php handles classes much better than
perl's blessed hashes

For the non OO and non module code. It's fairly simple

<snip> (Nice starting point, btw)

You have to do this:

$var['item'] instead of $var[item] except in php heredocs where you
leave out the quotes. That was maddening to find.

Perl accesses hash keys using {} curly braces, not brackets.

    my %hash = ('a'=>'foo', 'b'=>'bar'); # no lexical scoping in PHP
    print $hash{b} if exists $hash{b};
    print $hash{'b'} if exists $hash{'b'}; # also works

PHP also doesn't have special variable declarations that distinguish
from scalars, arrays, and hashes.

    <?php
    $string = 'scalar';
    $array = array('a','b','c');
    $hash = array('a'=>'foo', 'b'=>'bar');

    echo isset($hash['b']) ? $hash['b'] : '';
    ?>

Parens are always required in PHP, and it's generally a bit more
"rigid-feeling" when coming from Perl. However, it is just as capable,
once you get to know it.

So dive into some php and perl books.  I use O'Reilly's Programming
PHP and Programming Perl (aka The Camel book).  It will teach you the
flavor and subtile differences between the languages (early versions
of php were written in perl).  It also depends on if the code is OOP
or straight procedural. php4 used pass-by-value for it's default
function passing.  php5 uses pass-by-reference.

Good luck, but then I guess that's why you get paid the big bucks...

@OP: Why are you rewriting in PHP? If it works in Perl, and if it's
what you know, rewriting to PHP would be inefficient, and
counter-intuitive. Pretty much all hosting companies should have Perl
available.

--
Curtis- Hide quoted text -

- Show quoted text -

Hi Curtis

The reason for the rewrite is because a large chunk of the ancilary
functions have been written in php by others for its ease of accessing
the postgress database. If I leave this in perl I have to write the
code to talk to the database, recreating what they did, and having 2
different pieces of code that talks to the database for maintenance.
The easiest thing is to rewrite routines in perl to php.

Searching php.net Ifind exampls of code that is almost word for word
what I am already doing in perl, so it will not be much of an issue to
rework it. But when working with new languages, you never know what
that language may have available, maybe a simple command that does
what I want.

Bill H
.



Relevant Pages

  • Re: Any good Perl coders out there?
    ... I need to convert a PHP script into Perl. ... do is check out the DBI and DBD modules at your friendly neighborhood CPAN ... DBD is the actual database driver for it. ...
    (comp.lang.perl.misc)
  • Re: What are the differences between Perl and PHP when handling with Web pages
    ... What are the differences between Perl and PHP? ... anyway for the sake of good programming practice. ... I end up using PHP more for web development than PHP. ...
    (perl.beginners)
  • Re: Weird login, possibly related to rootkit Q
    ... breaks most of the scripts used by the web page server (this box is its ... database) and that would require a lengthy rewrite of the php stuff on ...
    (Linux-Kernel)
  • Re: Can a Perl Programmer Pick up PHP quickly?
    ... PHP is not easier compared to Perl. ... a language with fewer features is going to be easier to ... You can't call documentation guessed after the source not good ...
    (comp.lang.perl.misc)
  • Re: 64bit vs i386
    ... If it's just running apache, perl, and php what are the benefits and ... this really a LAP - Linux, Apache, PHP - system?) ... The MySQL is on a different server - so it is a LAP though php and perl ... Is the database 2TB? ...
    (Debian-User)