Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » PHP

Coverting perl to php

 
Jump to:  
 
Bill H
PostPosted: Wed Sep 03, 2008 7:25 pm    Post subject: Coverting perl to php
       
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
 

 
Michael Vilain
PostPosted: Wed Sep 03, 2008 7:27 pm    Post subject: Re: Coverting perl to php
       
In article
<0a67ee87-6cd0-47a5-9325-11b40244e4c2@v13g2000pro.googlegroups.com>,
Bill H <bill@ts1000.us> wrote:

Quote:
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.

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...

--
DeeDee, don't press that button! DeeDee! NO! Dee...
[I filter all Goggle Groups posts, so any reply may be automatically by ignored]
 

 
Jeff
PostPosted: Wed Sep 03, 2008 8:30 pm    Post subject: Re: Coverting perl to php
       
Michael Vilain wrote:
Quote:
In article
0a67ee87-6cd0-47a5-9325-11b40244e4c2@v13g2000pro.googlegroups.com>,
Bill H <bill@ts1000.us> 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

eq -> ==
foreach my $item(@items) -> foreach($items as $item)
my $var{item1} -> $var['item1']
@X = ('one','two')-> $X = array('one','two');
require -> require_once, use that also for "use" and "do"

Much is the same.

Things I had to look out for:

There is no $var ||= shortcut
There is no q{ or qq{

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.

There is no 'fatalsToBrowser', debugging is very different.

you can't do this: ... $var = 1}
you have to have an ending semicolon
....$var =1;}

PDO is the closest thing to DBI

There is no CGI.pm

There is no $X =~s/... use the preg stuff instead

Jeff



Quote:

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...
 

 
Curtis
PostPosted: Thu Sep 04, 2008 8:34 am    Post subject: Re: Coverting perl to php
       
Jeff wrote:
Quote:
Michael Vilain wrote:
In article
0a67ee87-6cd0-47a5-9325-11b40244e4c2@v13g2000pro.googlegroups.com>,
Bill H <bill@ts1000.us> 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)

Quote:
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.

Quote:
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
 

 
C. (http://symcbean.blogs
PostPosted: Thu Sep 04, 2008 12:16 pm    Post subject: Re: Coverting perl to php
       
On 3 Sep, 20:25, Bill H <b...@ts1000.us> wrote:
Quote:
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

<?php

$src="/path/to/some_file.mp3";

if (file_exists($src)) {
header('Content-type: audio/mpeg');
readfile($src);
} else {
header('HTTP/1.0 404 Not Found');
print "Whoops!\n";
}

?>

Note that the above is not actually streaming - just writing the file
to the browser. Have a google for progresive download for how to
emulate streaming across HTTP.

As for determining mime-type for a arbitary file - it depends on your
OS and webserver - but most have a mime-types file which maps file
extensions to mime types. Or, if you're running on a Unix/Linux system
you can call the 'file' command from PHP to get the mime-type (see man
file for more info).

C.
 

 
Jeff
PostPosted: Thu Sep 04, 2008 12:53 pm    Post subject: Re: Coverting perl to php
       
<snip>
Quote:

@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.

Yes, they do.

But I was losing work, with perl. And I think that little development
is going on in perl.

I have a series of utilities (a perl module that I'm writing as a php
class) that do the normal sorts of stuff and since all new code is in
php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend
that said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Jeff
Quote:

--
Curtis
 

 
Curtis
PostPosted: Thu Sep 04, 2008 10:53 pm    Post subject: Re: Coverting perl to php
       
Jeff wrote:
Quote:
snip

@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.

Yes, they do.

But I was losing work, with perl. And I think that little development
is going on in perl.

I see, that's unfortunate. However, the Perl community is very much
alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.

Quote:
I have a series of utilities (a perl module that I'm writing as a php
class) that do the normal sorts of stuff and since all new code is in
php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend that
said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Fair enough. :-)

--
Curtis
 

 
Bill H
PostPosted: Fri Sep 05, 2008 12:30 am    Post subject: Re: Coverting perl to php
       
On Sep 4, 6:34 am, Curtis <dye...@gmail.com> wrote:
Quote:
Jeff wrote:
Michael Vilain wrote:
In article
0a67ee87-6cd0-47a5-9325-11b40244e...@v13g2000pro.googlegroups.com>,
 Bill H <b...@ts1000.us> 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
 

 
Jeff
PostPosted: Fri Sep 05, 2008 8:18 pm    Post subject: Re: Coverting perl to php
       
Curtis wrote:
Quote:
Jeff wrote:
snip

@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.

Yes, they do.

But I was losing work, with perl. And I think that little
development is going on in perl.

I see, that's unfortunate.

I thought so. I thought I held out too long. Far too long.

However, the Perl community is very much
Quote:
alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.

No kidding! I really thought that was a never going to happen. Is it
going to be written in C++ instead of C?

OK, I just googled, and I saw nothing post 2005 :-(

I've always liked the brevity of perl. It's written for speed (in
programming) and as they say, more than one way to do it. I never found
anything I couldn't do that I wanted to do. And DBI rocks!
Quote:

I have a series of utilities (a perl module that I'm writing as a
php class) that do the normal sorts of stuff and since all new code is
in php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend
that said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Fair enough. Smile

The only thing I can say now is that I'm glad I never learned php4
specific stuff! Now if php6 would just toss in some of my favorite perl
bits...

Jeff

Quote:

--
Curtis
 

 
Curtis
PostPosted: Sun Sep 07, 2008 6:38 am    Post subject: Re: Coverting perl to php
       
Jeff wrote:
Quote:
Curtis wrote:
Jeff wrote:
snip

@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.

Yes, they do.

But I was losing work, with perl. And I think that little
development is going on in perl.

I see, that's unfortunate.

I thought so. I thought I held out too long. Far too long.

However, the Perl community is very much
alive, and many new things are on the way for Perl 6; so it is
definitely still under active development.

No kidding! I really thought that was a never going to happen. Is it
going to be written in C++ instead of C?

OK, I just googled, and I saw nothing post 2005 Sad

Perl 6 has been under development for almost 10 years, apparently. A
brief Google search turned up this FAQ about Perl 6:

<URL:http://dev.perl.org/perl6/faq.html>

As for the community, if you try perlmonks or other such places, I
would imagine them quite active. I'm not really active in the Perl
community, so I can't say for sure.

Perl 5 is very stable, so changes are quite rare and minimal.

Quote:
I've always liked the brevity of perl. It's written for speed (in
programming) and as they say, more than one way to do it. I never found
anything I couldn't do that I wanted to do. And DBI rocks!

I have a series of utilities (a perl module that I'm writing as a
php class) that do the normal sorts of stuff and since all new code
is in php, I need the utility to match. I'm not rewriting existing apps.

Gives me the chance to improve on what I had done. I had a friend
that said that you should throw out the first two code versions!

I much prefer the php class idea over the perl module.

Fair enough. :-)

The only thing I can say now is that I'm glad I never learned php4
specific stuff! Now if php6 would just toss in some of my favorite perl
bits...

Jeff

The last I read of PHP 6 features was from a meeting between the devs
in 2005, although you can download snaps of the current state of PHP 6
right now.

--
Curtis
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

Projekty domów zakłady bukmacherskie katalog firm gry dla dziewczyn Aranżacja wnętrz