stumpy Posted January 12, 2003 Report Share Posted January 12, 2003 Hi, I can program Perl but now I'm learning php. Are functions to php as subroutines are to Perl. For example I often start scripts in Perl with a choice if ($input{'action'} eq "add") {&add} if ($input{'action'} eq "delete") {&delete} etc, etc In php would it be good architecture to start do something similar if ($input{'action'} eq "add") {function add()} I appreciate your thoughts. Link to comment Share on other sites More sharing options...
khunsanuk Posted January 13, 2003 Report Share Posted January 13, 2003 Hi, Not certain if you can use 'eq', but other than that it looks pretty okay. Don't forget to add a semi-colon after the function call though. I would write the line like this: if ($input == "add") { function add(); } Also, not quite certain what you mean with $input{'action'} Sanuk! Link to comment Share on other sites More sharing options...
stumpy Posted January 13, 2003 Author Report Share Posted January 13, 2003 Hi, Thanks for the answer. Not finding the switch from Perl to php as easy as I thought... The $input{'action'} is a commonly used way of parsing user input in Perl and reading it into a hash (array to you) and refering to the elements. SD. Link to comment Share on other sites More sharing options...
khunsanuk Posted January 14, 2003 Report Share Posted January 14, 2003 Hi, "Not finding the switch from Perl to php as easy as I thought..." Strange, it took me only a couple of hours to get going with PHP. Of course the fact that I had already programmed in about 7-8 other languages helped "The $input{'action'} is a commonly used way of parsing user input in Perl and reading it into a hash (array to you) and refering to the elements." Ah, arrays in PHP are written like this: $array{0} or $array{"identifier"} (The {} should be square, but I think the board won't let me) Sanuk! Link to comment Share on other sites More sharing options...
gobbledonk Posted January 14, 2003 Report Share Posted January 14, 2003 Gentlemen, There are at least half a million sites dedicated to PHP, and I believe this is the best for code snippets AND an illustration of good coding style : PHP Builder As KS mentioned, PHP is normally pretty easy for anyone from a Perl (or C or Java or ...) background, although I did find their implementation of multidimensional hashes to be a little less intuitive than Perl's. Cant beat PHP for speed , though - it absolutely rocks. Enjoy. Link to comment Share on other sites More sharing options...
khunsanuk Posted January 14, 2003 Report Share Posted January 14, 2003 Hi, "Cant beat PHP for speed , though - it absolutely rocks." I agree. At the office we use mostly ASP, but I *much* prefer PHP. Can't really put my finger on it, but it just feels so much more natural. I don't think I could have written the bargirl game in 9 days if I had tried using ASP. Sanuk! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.