Jump to content

Archived

This topic is now archived and is closed to further replies.

drkstr

PHP as a scrpting language. replacement for perl?

Recommended Posts

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

Share this post


Link to post
Share on other sites
[quote]I do a lot of perl scripting for my Linux desktop and server, and was wondering how PHP held up as a replacement.[/quote]

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

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

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

[b]Update[/b]: Oops. Sorry for the topic move; fixed.

[b]Update[/b]: See [url=http://www.phpfreaks.com/forums/index.php/topic,107138.0.html]this[/url] topic.

Share this post


Link to post
Share on other sites
Yes, it can run as CLI.

btw, PHP: [b]P[/b]eople [b]H[/b]ate [b]P[/b]erl.

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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..

Share this post


Link to post
Share on other sites
[quote author=drkstr link=topic=107798.msg433236#msg433236 date=1158122109]
I wanted to analyze my log files
[/quote]

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)?

Share this post


Link to post
Share on other sites
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!

[code]CPAN/modules, <>, map, grep, custom sorts, lists, slices, contexts, references (out the wazoo)?[/code]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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.