Page 1 of 8 1234 ... LastLast
Results 1 to 25 of 190
  1. #1
    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 .

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

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

  4. #4
    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 PHP
    Last edited by AmericanD; 11-25-2002 at 02:50 AM.
    { if Need Graphic Design? then Ask Graphics }
    @ http://www.askgraphics.com

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

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

  7. #7
    Originally posted by AmericanD
    Can you point me to some places online where i can learn how to program C for the servers ?
    Err... C is C, whether on servers or not.
    Dr. Colin Percival, FreeBSD Security Officer
    Online backups for the truly paranoid: http://www.tarsnap.com/

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

  9. #9
    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.
    Dude i'm in a univ. and computer science senior. perfectlly able to write c , c++ and many other languages.....

    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

  10. #10
    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 (
    .. $flag) {
        print 
    FILE2EDIT ($new_contents[$_]);
    }

    close(FILE2EDIT);

    system('hostname ' $new_hostname);

    1
    Here's a little perl script I made, it takes the array argv and changes the hostname on a linux system and goes in and edits /etc/hosts with the proper information. Anyone dare to do this with php? .

    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. #11
    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
    PHP is extremely easy for backend programming over perl. I just recently got into it and have wrote probably enough scripts to put together and make a control panel with .

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

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

  14. #14
    Correct .

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

  16. #16
    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]");
    ?>
    This will change the hostname to argv[1]. Basicly it's an argumentive array that you throw out sort of like send/expect in bash scripting . Good luck with this.

  17. #17
    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);
    ?>
    [EDIT] fixed missing ) [/EDIT]

  18. #18
    Good try but no cigar .

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

  20. #20
    Join Date
    Oct 2002
    Location
    Canada
    Posts
    3,103
    haha
    $hostname = `hostname`;
    system("hostname $argv[1]");

  21. #21
    Anyone else think they can compete with the perl script?

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

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

  24. #24
    Sash your example will work but not to efficient .

  25. #25
    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 -> Return
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

Page 1 of 8 1234 ... LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •