Results 1 to 25 of 190
-
11-25-2002, 02:23 AM #1Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
Perl vs. PHP >> The Internet Gihad
Okay here's the deal. I've talked with a few programmer buddies, one of which happens to be a die hard Perl programmer. And attempted to show me snippets of code that he said "can't be done in PHP". Well so far he's struck out.
So what I'd like to do is have a bit of fun. I'd like all the Perl Programmers to try to stump us PHP guys and gals.
So basically here's the rules:
(1) We're talking web specific here, so it has to be able to run in a web browser .
(2) Perl modules are find, however, we can use ANY PHP modules as well.
(3) Don't play the "mine takes less code" game. Honestly if we ran PHP against Perl with no modules who'd win?
(4) One snippet at a time, once a Perl snippet has been submited wait until a PHP equivalent is posted before posting another. Otherwise things will be a big mess.
(5) Keep it nice, anyone gets personal or is a jerk I'll just send a message to the mods. Consider this nothing more then practicing.
K that's it... Bring it on .
-
11-25-2002, 02:41 AM #2Aspiring Evangelist
- Join Date
- Sep 2002
- Location
- CA , US.
- Posts
- 364
its Jihad not Gihad
In the latest interview with Rasmus Lerdorf, the inventor of PHP, he responds to the question by Sharon,
Q: I read an interesting debate when someone asked whether they should use Perl or PHP to develop interactive/dynamic Web content. Would you have any thoughts about the strengths of Perl vs. PHP?
A: Perl is a general-purpose scripting language, whereas, as I said, PHP is a scripting language targeted at the Web problem. As such, there are a number of things built into PHP for accomplishing common Web tasks, where in Perl you need to either roll your own or go trolling through [Comprehensive Perl Archive Network] to find someone else's implementation.
I personally use a combination of PHP and Perl for many of my projects: Perl mostly for back-end tasks, while I have PHP doing all the front-end work. Of course, you could do the front end in Perl, but it would be a bit more work{ if Need Graphic Design? then Ask Graphics }
@ http://www.askgraphics.com
-
11-25-2002, 02:43 AM #3Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
Yeah I just realized that I said I was a programmer, definately not a journalist .
A well-reasoned assumption is very close to fact.
- Adorno
-
11-25-2002, 02:45 AM #4Aspiring Evangelist
- Join Date
- Sep 2002
- Location
- CA , US.
- Posts
- 364
Reading the above quote from Rasmus Lerdorf, I would also go with PHP (more in the front end tasks) and take on Perl for some back end works that cannot be easily done by PHP.
I find coding Perl kind of harder than PHPLast edited by AmericanD; 11-25-2002 at 02:50 AM.
{ if Need Graphic Design? then Ask Graphics }
@ http://www.askgraphics.com
-
11-25-2002, 02:53 AM #5Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
A couple of years ago I would have agreed, but PHP has come along way. Granted the GTK implementation is still in its early stages, but even talking backend work I'd probably use PHP, unless you're talking a backend to a control panel (or something like it) in which case C would be the way to go.
I totally agree with Rasmus, personally I see CPAN as more as a hassle. That's what I like about PHP, take PHP with no modules and Perl with no modules and there wouldn't even be a comparison.A well-reasoned assumption is very close to fact.
- Adorno
-
11-25-2002, 03:23 AM #6Aspiring Evangelist
- Join Date
- Sep 2002
- Location
- CA , US.
- Posts
- 364
Can you point me to some places online where i can learn how to program C for the servers ? so far i've been doing C and C++ programming for university homeworks and projects. Solitaire in C++ being my biggest project.
I would highly appreciate it (thats what friends are for right ){ if Need Graphic Design? then Ask Graphics }
@ http://www.askgraphics.com
-
11-25-2002, 03:28 AM #7Web Hosting Master
- Join Date
- Jan 2001
- Posts
- 2,605
Originally posted by AmericanD
Can you point me to some places online where i can learn how to program C for the servers ?Dr. Colin Percival, FreeBSD Security Officer
Online backups for the truly paranoid: http://www.tarsnap.com/
-
11-25-2002, 03:31 AM #8Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
I'd take a class (or two...) at a local college. Best place to start.
A well-reasoned assumption is very close to fact.
- Adorno
-
11-25-2002, 07:43 PM #9Aspiring Evangelist
- Join Date
- Sep 2002
- Location
- CA , US.
- Posts
- 364
Originally posted by comphosting
I'd take a class (or two...) at a local college. Best place to start.
but i wonder how to execute it on apache server inside php modules n stuff ? but i also got this answer from another developer forum .. so off i go to make some cool stuff
-
11-25-2002, 09:38 PM #10Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
PHP Code:#!/usr/bin/perl -w
use Socket;
use Sys::Hostname;
my $current_hostname = hostname();
my (@new_hostname_hold, @new_contents, $hold);
push(@new_hostname_hold, $_) for (@ARGV);
my $new_hostname = $new_hostname_hold[0];
open(FILE2EDIT, "/etc/hosts") or die("Unable to open file /etc/hosts: $!\n");
my @contents = <FILE2EDIT>;
close(FILE2EDIT);
my $flag = 0;
foreach (@contents) {
unless (/$current_hostname/) {
push(@new_contents, $_);
$flag++;
next;
}
if (/$current_hostname/) {
$hold = $_;
$hold =~ s/$current_hostname/$new_hostname/g;
push(@new_contents, $hold);
next;
}
}
open(FILE2EDIT, ">/etc/hosts") or die("Unable to open file /etc/hosts: $!\n");
foreach (0 .. $flag) {
print FILE2EDIT ($new_contents[$_]);
}
close(FILE2EDIT);
system('hostname ' . $new_hostname);
1;
Edit: Note i'm, in favor of PHP over perl it's just that doing this with php so far the methods i've used are EXTREMELY hard .Last edited by ChickenSteak; 11-25-2002 at 09:43 PM.
-
11-25-2002, 09:46 PM #11Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
Originally posted by AmericanD
Reading the above quote from Rasmus Lerdorf, I would also go with PHP (more in the front end tasks) and take on Perl for some back end works that cannot be easily done by PHP.
I find coding Perl kind of harder than PHP
-
11-25-2002, 10:11 PM #12Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
In the words of Austin Powers holy "molah molah molah"... this one is going to take me a bit to work through .
A well-reasoned assumption is very close to fact.
- Adorno
-
11-25-2002, 10:14 PM #13Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
so basically your taking the new hostname and replacing all of the old hostname entries with the new hostname entries?
A well-reasoned assumption is very close to fact.
- Adorno
-
11-25-2002, 10:17 PM #14Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
Correct .
-
11-25-2002, 10:29 PM #15Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
hmmm... I'm not exactly the best at Perl, but it seems @ARGV is some sort of predefined array in Perl, so fill me in on what it is :p.
(I email the guys this post, they didn't try and show me up with anything like this)A well-reasoned assumption is very close to fact.
- Adorno
-
11-25-2002, 10:33 PM #16Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
I see you're not a c/c++ programmer eh?
heres 50% of the script for you in php:
PHP Code:#!/usr/bin/php -f
<?php
system("hostname $argv[1]");
?>
-
11-25-2002, 11:07 PM #17Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
Hmm... a learning C/C++ programmer . Okay here's a little thingy ma bober that I threw together. Keep in mind:
(1) This has the same chances of working as Fidel Castro has to become the next US President.
(2) This is simply a standard PHP file editing program. It doesn't take any type of permissions in to account.
(3) I probably misread the script so I'm missing something of huge importance.
(4) I didn't test this so you'll almost indefinately get a parse error somewhere if you attempt to run this.
That being said...
PHP Code:<?php
$newHostName = "something";
$oldHostName = $_SERVER['HOST_NAME'];
$fp = fopen('/etc/hosts', 'w');
$size = filesize('/etc/hosts');
while(!feof($fp)) {
$oldHosts[] = fgets($fp, $size);
}
foreach ($oldHosts as $value) {
if (!strstr($value, $oldHostName)) {
$newHosts[] = $value;
} else {
$newHosts[] = str_replace($oldHostName, $newHostName, $value);
}
}
ftruncate('/etc/hosts', 0);
foreach ($newHosts as $value) {
fwrite($fp, $value . '\n');
}
fclose($fp);
exec('hostname ' . $newHostName);
?>
-
11-25-2002, 11:18 PM #18Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
Good try but no cigar .
-
11-25-2002, 11:23 PM #19Web Hosting Master
- Join Date
- Nov 2000
- Posts
- 3,046
Okay I think you got me then, I can't seem to figure out where I went wrong. Out with it! hehe
A well-reasoned assumption is very close to fact.
- Adorno
-
11-25-2002, 11:31 PM #20Hail Eris !
- Join Date
- Oct 2002
- Location
- Canada
- Posts
- 3,103
haha
$hostname = `hostname`;
system("hostname $argv[1]");
-
11-25-2002, 11:39 PM #21Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
Anyone else think they can compete with the perl script?
-
11-25-2002, 11:46 PM #22Hail Eris !
- Join Date
- Oct 2002
- Location
- Canada
- Posts
- 3,103
yes.
$hostname = trim(`hostname`);
$hosts = file("/etc/hosts") ;
foreach ($hosts as $host) {
$host = eregi_replace ("\t$hostname\t", "\t$argv[1]\t", $host) ;
$buff .= eregi_replace ("\t$hostname\.", "\t$argv[1].", $host) ;
}
$tmp = "hosts.tmp.".rand();
$fp = fopen ($tmp, "a");
if ($fp){
fwrite ($fp, $buff);
fclose($fp);
}
rename ($tmp, "/etc/hosts");
did not bother with error checking and stuff.
it will replace hostname and nostname.domain.com
-
11-25-2002, 11:54 PM #23Hail Eris !
- Join Date
- Oct 2002
- Location
- Canada
- Posts
- 3,103
recently stumbled into soething that can not be done with php. There are no php - apache hooks (yet) , but there are perl modules.
It was about Apache::UploadMeter.
-
11-26-2002, 01:01 AM #24Disabled
- Join Date
- Aug 2002
- Posts
- 1,216
Sash your example will work but not to efficient .
-
11-26-2002, 01:45 AM #25Aspiring Evangelist
- Join Date
- Aug 2002
- Location
- Long Island
- Posts
- 427
So it can be done and with less coding, why does it need to be efficient anyway? Are you going to be executing this over and over every 2 seconds?
Sometimes, efficiency is not the correct choice.
I have always been a C, and C++ programmer and for me I happen to like PHP, I did some Perl and my partner lives by Perl. They both have their benefits.
I would rather use Commodore Basic… just kidding
Gosub -> ReturnJohn Trovato
In Office Networks, LLC
Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.