Jump to content

PHP as a scrpting language. replacement for perl?


drkstr

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
Link to comment
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.
Link to comment
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.
Link to comment
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)?
Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.