Perl way to do PHP includes?

G

Garry Heaton

Are the following Perl/PHP methods roughly equivalent in function and
efficiencey?

1. use Perl_package;
require_once(file.php);

2. open FILE, "< $perl_file";
include(file.php);

I'm trying to determine whether Perl/CGI.pm (no Embperl, Mason etc.) is
sufficient for converting PHP scripts without incurring serious inefficiencies.

Regards

Garry Heaton
 
E

Eric Schwartz

Garry Heaton said:
Are the following Perl/PHP methods roughly equivalent in function and
efficiencey?

1. use Perl_package;
require_once(file.php);

Vaguely. You should read the perlmod docs ('perldoc perlmod') to find
out exactly how this works. PHP just reads in the file and defines
all the functions in it in the global namespace; Perl lets you be more
fine-grained if you choose.
2. open FILE, "< $perl_file";
include(file.php);

Not even close. Did you read the Perl docs for open() to see what it
does?
I'm trying to determine whether Perl/CGI.pm (no Embperl, Mason etc.) is
sufficient for converting PHP scripts without incurring serious inefficiencies.

The question to be sure you've answered is why convert them if they're
working now? Assuming you have a good reason, then it's best to have
a good understanding of both languages. perldoc perlbook for more
details about learning Perl.

-=Eric
 
G

Garry Heaton

Eric said:
Vaguely. You should read the perlmod docs ('perldoc perlmod') to find
out exactly how this works. PHP just reads in the file and defines
all the functions in it in the global namespace; Perl lets you be more
fine-grained if you choose.




Not even close. Did you read the Perl docs for open() to see what it
does?




The question to be sure you've answered is why convert them if they're
working now? Assuming you have a good reason, then it's best to have
a good understanding of both languages. perldoc perlbook for more
details about learning Perl.

-=Eric

Sorry, should have followed-up:

2. open FILE, "< $perl_file";
while (<FILE>) {
print;
};

Garry
 
G

Garry Heaton

Garry said:
Sorry, should have followed-up:

2. open FILE, "< $perl_file";
while (<FILE>) {
print;
};

Garry

Or maybe even:

2. open FILE, "< $perl_file";
while (<FILE>) {
print;
}

Garry
 
T

Tad McClellan

Garry Heaton said:
2. open FILE, "< $perl_file";


You should always, yes *always*, check the return value from open():

open FILE, $perl_file or die "could not open '$perl_file' $!";
 
E

Eric Schwartz

Garry Heaton said:
Or maybe even:

2. open FILE, "< $perl_file";
while (<FILE>) {
print;
}

These are still completely different from include('file.php') in PHP.
It might not hurt to read the PHP docs to understand what include()
does, and why it's not the same thing as what you just printed above.

-=Eric
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top