Beginner Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsOtherBeginner Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 16th, 2003, 08:35 AM
opulyst opulyst is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 13 opulyst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 36 sec
Reputation Power: 0
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.

Reply With Quote
  #2  
Old March 17th, 2003, 09:02 AM
trevHCS trevHCS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 80 trevHCS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Quote:
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?


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/

Reply With Quote
  #3  
Old March 17th, 2003, 09:49 AM
opulyst opulyst is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 13 opulyst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 36 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old March 17th, 2003, 04:05 PM
trevHCS trevHCS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 80 trevHCS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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

Reply With Quote
  #5  
Old March 17th, 2003, 04:16 PM
opulyst opulyst is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 13 opulyst User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 36 sec
Reputation Power: 0
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

Reply With Quote
  #6  
Old March 17th, 2003, 06:16 PM
Ctb's Avatar
Ctb Ctb is offline
An Ominous Coward
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2002
Posts: 4,425 Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 10 h
Reputation Power: 0
Quote:
do it as PHP and preach the virtues of this language to the masses of Perl users out there
That door swings both ways m8 - and you asked for it!

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.

Reply With Quote
  #7  
Old March 17th, 2003, 07:14 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 18
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
re: ctb's rant

^^^^^ blah blah blah blah blah blah blah. bleh blah bleah. yeah.
__________________
And you know I mean that.

Reply With Quote
  #8  
Old March 17th, 2003, 08:57 PM
Ctb's Avatar
Ctb Ctb is offline
An Ominous Coward
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Jan 2002
Posts: 4,425 Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level)Ctb User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 3 Weeks 10 h
Reputation Power: 0
//LOL

The best part is.... how do you argue back to that?

Reply With Quote
  #9  
Old March 17th, 2003, 09:12 PM
mttatkns mttatkns is offline
Got source?
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Mar 2003
Location: Laguna Niguel, California, USA
Posts: 2,332 mttatkns User rank is Private First Class (20 - 50 Reputation Level)mttatkns User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
My un-biased opinion: you don't

Reply With Quote
  #10  
Old March 18th, 2003, 09:11 AM
trevHCS trevHCS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 80 trevHCS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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!

Reply With Quote
  #11  
Old March 18th, 2003, 09:40 AM
Hero Zzyzzx's Avatar
Hero Zzyzzx Hero Zzyzzx is offline
11
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Jul 2001
Location: Lynn, MA
Posts: 4,635 Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level)Hero Zzyzzx User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 4 Days 23 h 44 m 19 sec
Reputation Power: 77
Send a message via AIM to Hero Zzyzzx
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.

Reply With Quote
  #12  
Old March 18th, 2003, 03:52 PM
trevHCS trevHCS is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 80 trevHCS User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsOtherBeginner Programming > Converting PHP Script to Perl?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |