|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Converting PHP Script to Perl?
Hello,
I wrote a simple php script that does a special math algorithm. It has nothing more than multiplication and addition, no loops at all. I do not know a lick of Perl, but I have had some people ask me if I could do the same script in Perl or CGI My question is how easy is it to change over the script to Perl? Can I just change the variable structure? Is there a more involved process? It is a form script, so the html page sends info to php page. Very basic. Thanks in advance. |
|
#2
|
|||
|
|||
|
Quote:
Quick answer - fairly simple if you know Perl... Before you hit me however, heres a Perl crash course: 1) You need to start Perl files with: #!/usr/bin/perl -w ....which needs changing to the appropriate path (ask your hosting company). 2) Variables are the same as in PHP, but arrays start with @ instead of $ and associative arrays start with % 3) For comments use # not /* */ (Note, the # in 1 is required!) 4) Somewhere at the top of the file put: use CGI; use CGI::Carp qw(fatalsToBrowser); The first one makes forms easier and the second one gives you more useful error messages rather than error500. This assumes you have cgi.pm installed, but most hosts will have. 5) To collect form input try this: $query = new CGI; $form_input1 = $query->param("FormBox"); $form_input2 = $query->param("FormBox2"); "FormBox" is the name of the form element, like you could use $_POST['FormBox'] in PHP. 6) Before printing (or near the top of the script) put: print "Content-type: text/html\n\n"; ...otherwise you'll get errors. 7) Finally, remember to put the Perl scripts into your CGI-bin and chmod them to 755. Oh and good luck! Trev PS: Sure you want to mess with Perl? -- http://www.aardvarktravel.net/ |
|
#3
|
|||
|
|||
|
Maybe I don't?
Trev,
Thanks for the quick response. Although these changes do not really scare me for changing this over, the pathway deal and the CHMOD are two things that the people who want it in Perl will have so much trouble with. They need something that is as simple as uploading the files and cut and paste the link html. Do you have any suggestions as to something that would work this way? Again thanks, Jason |
|
#4
|
|||
|
|||
|
Is this going to be run on other peoples servers or just from yours? If its other peoples, you'd need some way of changing the shebang line to suit, although from memory there are only about 3 that are generally used. Shebang line btw is the one at the very top that gives the path to Perl.
Probably the easiest way for the users is to use an installer script, eg: - You send them installer.pl and perl_script.txt - Perl_script.txt is the Perl script, but with the shebang line placement written in as {shebang} - They run installer.pl and choose from 3 possible shebang lines - You then read the perl_script.txt into a variable and replace the {shebang} with the appropriate value - The file is then written out as perl_script.pl - The installer finally chmod's the file to 755 That way all they need to do is choose the appropriate path to perl, upload 2 files and run the installer. Admittidly it still means they need to know the path, but that can be got from system admin. Alternatively, they could try running the script and if it gives error500 then they just run the installer again and try another one. I could imagine it might be possible to find Perl by running the "whereis perl" command from the installer, but I can't remember enough Perl to tell you how to do that. Probably the folks in the Devshed Perl Forum could help there... Oh and if you want the easiest way - do it as PHP and preach the virtues of this language to the masses of Perl users out there! Trev |
|
#5
|
|||
|
|||
|
Trev,
Thanks...after reading your post, I have come to the following conclusion. It is written in PHP, so I am starting to preach... Thanks, Jason |
|
#6
|
||||
|
||||
|
Quote:
![]() Namespace support Perl 1 PHP 0 OOP structures Perl 1.5 PHP 0 Okay, so they can both be a pain the rump, but PHP is a MUCH bigger pain. Extensions Perl 3 PHP 0 NO contest in PEAR vs. CPAN Embedding Perl 3 (it can be done, but man does it get ugly) PHP 1 (alright! PHP is on the board!) Usability Perl 3 (no one is going to claim that using Perl properly is easy) PHP 1.5 (PHP is just a bunch of functions... you don't really "use" it, so it doesn't get a whole point) "Community Mindedness" Perl 4 (Perl can play with ALMOST EVERYTHING you can think of [whether it should or not..]) PHP 1.5 (Sorry... nice integration with MySQL and PostgreSQL doesn't even compare to the DBI, let alone all of Perl) Raw Power Perl 5 PHP 1.5 NO contest. RAD Perl 6 PHP 3 Both can do rapid application development as long as you use them properly, PHP just slightly better than Perl. Conclusion I personally like Perl better whether you agree or not. While it was fun to bash PHP for a moment, I'm not being serious. I think they're both nice little languages, I just personally like Perl much much better and use it a great deal more. If PHP works for the job, however, by all means use it. Just remember that pretty much everything (if not everything) PHP can do, so can Perl, and therefore there's rarely a good reason to choose PHP over Perl if you know Perl better than PHP (unless you don't have mod_perl available for some reason)! THAT, my friends, is why you're not going to "convert" too many people who actually know how to use Perl. |
|
#7
|
||||
|
||||
|
re: ctb's rant
^^^^^ blah blah blah blah blah blah blah. bleh blah bleah. yeah.
![]()
__________________
And you know I mean that. |
|
#8
|
||||
|
||||
|
//LOL
The best part is.... how do you argue back to that? |
|
#9
|
|||
|
|||
|
My un-biased opinion: you don't
|
|
#10
|
|||
|
|||
|
Unfortunately opulyst, in your mission to preach the word that is PHP you will come across those who by their own admission have played with the darkside of programming for far too long to be converted.
Erm oh and remember, those from the darkside will use all sorts of temptations to convince you that their Perl is better. Just remember one thing - PHP has php.net and Perl appears to have "manpage perl" which is not much good for those Windows users out there... However to prove that I am not completely biased, I will admit that when it comes to system stuff Perl spreads PHP on a piece of toast and eats it! Oh and its also better for chmod and has the tainted data switch....but....erm... Trev - not very good PHP programmer, even worse with Perl! |
|
#11
|
||||
|
||||
|
If you absolutely HAVE to view documentation in pretty CSS-enabled pages with an enormous HTML-rendering client behind it, you can always go to:
http://www.perldoc.com/ Myself, I *really* like being able to get ALL perl documentation from a terminal, very handy when I've got shells open to different servers all over the place, or when I'm using my laptop away from 'net access- I automatically have all the most current documentation locally. Until you've embraced the CLI, you're going to be less productive. I use both, I like both. I like perl better. |
|
#12
|
|||
|
|||
|
Didn't know about that site when I last played around with Perl, but looks quite handy, if a little lacking in nice graphics, CSS etc...
As for browsers, yes I admit even I use IE these days - quite a bit easier for those of us born into a Windows world which I'd guess is why Perl seems harder than for anyone familiar with Linux/Unix whatever mainframes used to run on. Now why can't Perl be more English, like Intercal: http://www2.latech.edu/~acm/helloworld/Intercal.html ...especially like the last command in that "hello world" program. Trev |
![]() |
| Viewing: Dev Shed Forums > Other > Beginner Programming > Converting PHP Script to Perl? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|