Jump to content


Photo

PHP as a scrpting language. replacement for perl?


  • Please log in to reply
7 replies to this topic

#1 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 12 September 2006 - 04:26 PM

I do a lot of perl scripting for my Linux desktop and server, and was wondering how PHP held up as a replacement.

Does is support command line parameters? If so, how are the accessed in the PHP script?

Also, does it support a shebang ( #!/usr/bin/php at the top of the file ), or do I have to tell it to run the script manually with 'php script name'?

I would like to start doing my scripting in PHP since it's a much better language. Any input would be appreciated.

Thanks!
...drkstr

#2 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 12 September 2006 - 04:39 PM

I do a lot of perl scripting for my Linux desktop and server, and was wondering how PHP held up as a replacement.


What kind of scripting? Yes--PHP supports all of these things.

I would like to start doing my scripting in PHP since it's a much better language.


It's a much different language. I do things in Perl that I wouldn't even try in PHP.

Update: Oops. Sorry for the topic move; fixed.

Update: See this topic.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#3 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 12 September 2006 - 04:39 PM

Yes, it can run as CLI.

btw, PHP: People Hate Perl.

(though you'll never find that officially stated anywhere.)

#4 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 13 September 2006 - 04:35 AM

Thanks for the link. After a litle bit of reading up on the pros/cons, I don't think I'm ready to give up on perl quite yet. I am going to give it a shot for this project however. I wanted to analyze my log files and store info in a database, and I think I can put my new found PHP knowledge to use with this.

After some more reading, I found what I needed to get started. $argc is the number of arguments, and $argv is an array that contains command line arguments.

Thanks for the pointer to the right direction!
...drkstr

**edit**
Just wanted to clear something up. I meant no disrespect when I said PHP was a better language. perl was actually my first language, so it will always hold a place in my heart. I'm a big OOP person however so I was excited when I started learning PHP. For the same reason, I'm thinking of picking up python at some point.

#5 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 13 September 2006 - 07:31 AM

I've found perl to be considerably faster for regexp processing.  Your mileage may vary.

As far as features go, PHP has them all.  There's a few getopts (Console::Getopt and just plain 'getopt).  And there's no features I've found missing..

#6 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 13 September 2006 - 02:15 PM

I wanted to analyze my log files


What does this involve? Lots of regex? Analyzing log files is where Perl excels. Out of curiosity, how many years have you been using Perl? Have you grasped/used the more advanced features, e.g., CPAN/modules, <>, map, grep, custom sorts, lists, slices, contexts, references (out the wazoo)?
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/

#7 drkstr

drkstr
  • Members
  • PipPipPip
  • Advanced Member
  • 66 posts
  • LocationSeattle, WA - USA

Posted 14 September 2006 - 01:27 AM

It actually does involve a bit of log analizing, which perl is great for. I wanted to give php a shot with this project though, just to se  how it held up. The thing I really liked about PHP was how easy it was to take it to the next level. I started out doing a simple log mining to building an andvanced method for generating data reports based on whatever criteria you want, date ranges, IP ranges, service protocols, or a combenation thereof. I'm not saying this isn't possible in perl, but I think in a very object oriented kind of way and it was easire for me build complex data objects in this mindset, then the more linear perl approach. I am however, going to stick to perl for the simpeler tasks since I like it's low level syntax more. And it's regex kicks!

CPAN/modules, <>, map, grep, custom sorts, lists, slices, contexts, references (out the wazoo)?
Not to long, I've only been using Linux for about a year now. Never I am a big fan of all the other trickery you mention though. Building objects as multidemensional arrays was fun (that is, if you like pain ..which I do). I guess I should look into some more of the advanced features you mentioned, such as 'map' (not really sure what that is).

Thanks for the replies! This has been a fun learning process for me!
...drkstr

#8 effigy

effigy
  • Staff Alumni
  • Advanced Member
  • 3,600 posts
  • LocationIL

Posted 14 September 2006 - 01:32 AM

Enjoy the adventure--I'd like to see what you come up with. Perl does have OOP, but not as "officially" as others, including PHP. I encourage you to strengthen your knowledge of both languages.
Regexp | Unicode Article | Letter Database
/\A(e)?((1)?ff(?:(?:ig)?y)?|f(?:ig)?)\z/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users