Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Easier web programming language: PERL or PHP?

Reply
Thread Tools

Easier web programming language: PERL or PHP?

 
 
Jim Michaels
Guest
Posts: n/a
 
      01-14-2006
I know this is a PERL group, but having worked with PERL and PHP, I've
chosen to work with PHP for web apps.
the syntax & basic functions are similar to C/JavaScript. It has PERL's
regexps. It's far from a toy language. It has objects too.
Forms variables are broken down into $_GET['name'], $_POST['name'] or
$_REQUEST['name'] and there are $_SERVER[] variables.
database access is comparably simple. (and with PHP, well integrated) for
instance, a MySQL database would look like
<?php
$link=mysql_connect("server", "username", "password");
mysql_select_db("database", $link);
//from here on, you can use the same shared database connection ($link) for
the rest of your queries.
$q=mysql_query("SELECT fruit_id,fruit FROM fruits ORDER BY fruit", $link);
echo "<select name=selectbox size=1>";
$count=0;
while ($row=mysql_fetch_array($q)) {
if (0==$count) { //make sure first item is selected
$selected="selected";
} else {
$selected="";
}
echo "<option $selected value=\"$row[fruit_id]\">$row[fruit]</option>";
$count++;
}
echo "</select>\n";

//or it can be as simple as
$q2=mysql_query("SELECT fruit_id,fruit FROM fruits ORDER BY fruit", $link);
echo "<select name=selectbox size=1>";
while ($row=mysql_fetch_array($q2)) {
echo "<option value=\"$row[fruit_id]\">$row[fruit]</option>";
}
echo "</select>\n";
?>

I didn't have to make this example look as complicated as I did, but the
first one is more useful.
The first 2 lines are often stuck into an inc.php file (include 'inc.php'
and used wherever a database connection is needed, along with any
database-related or personal library functions like conversion stuff and
functions to pull variables out of databases for configuration purposes.
string manipulation is relatively easy, and there's a good library in place.
It has the GD graphics library so you can resize and manipulate JPEGS and
GIFS or create them.
many of the things you have to install into PERL come installed by default
into PHP.
Installing new things into PHP is NOT as easy as installing a PERL package
with ppm(PERL package manager) though. Few need to.
PERL is arguably more terse when it comes to manipulation of text. and more
powerful.
PERL has Email::Valid package to validate email addresses. there is a less
powerful PHP codebase for email validation out there.
PERL has packages organized into one place (CPAN). PHP code is scattered in
repositories throughout the globe and you have to dig to find things.

ASP is for people who like BASIC (simple, not very powerful) and working
with ADO and installing/working with ActiveX controls on the server. You
also end up working with URL variables a lot (GET). There are fewer ASP
servers (and they cost more than PHP/MySQL). But if you are looking for a
job, learn ASP.NET! Corporate america wants it!

As for ColdFusion, those servers are very expensive and few in number. Once
in a while I see a job that uses ColdFusion. But I haven't seen a job
except once that uses PHP. (why?) ColdFusion has a script language, but
mostly it's for people who have a hard time with programming lanugages but
understand tags. Think of it as tags that do things on the server but are
not seen by the browser. Its scripting language also similar to BASIC.
<CFIF rags=1> <CFELSE> </CFIF> if I remember right is one example, another
is <CFLOOP> </CFLOOP> but it's been a long time.

As for your PHP code request, I think it would look like this (I suggest you
have one of your radio buttons SELECTED):
(Your form will not work without a submit button. so I added one.)
<?php
if (isset($_GET['volume']) && isset($_GET['weight'])) { //if both have
something selected... process the form.
//Courier "yellow" - for volume 1, 2 and 3:
if ($_GET['weight']===100) { echo "courier &quot;yellow&quot;
rate=600<br>\n"; }
if ($_GET['weight']===200) { echo "courier &quot;yellow&quot;
rate=900<br>\n"; }
if ($_GET['weight']===300) { echo "courier &quot;yellow&quot;
rate=1200<br>\n"; }

//Courier "blue" - for volume 1 and 2:
if ($_GET['volume']===1 || $_GET['volume']===2) {
if ($_GET['weight']===100) { echo "courier &quot;blue&quot;
rate=400<br>\n"; }
if ($_GET['weight']===200) { echo "courier &quot;blue&quot;
rate=700<br>\n"; }
}

//Courier "black" - for volume 2 and 3:
if ($_GET['volume']===2 || $_GET['volume']===3) {
if ($_GET['weight']===100) { echo "courier &quot;black&quot;
rate=800<br>\n"; }
if ($_GET['weight']===200) { echo "courier &quot;black&quot;
rate=1100<br>\n"; }
if ($_GET['weight']===300) { echo "courier &quot;black&quot;
rate=1500<br>\n"; }
}
} else { //display form. possibly not all radio buttons were selected.
//(break out of php and output plain HTML for a while.)
?>
<form method="GET" action="output.php" name="input">
SELECT THE VOLUME OF YOUR PACKAGE:<br>
<input type="radio" name="volume" value="1"> from 0 to 1 m3<br>
<input type="radio" name="volume" value="2"> from 1 to 2 m3<br>
<input type="radio" name="volume" value="3"> from 2 to 3 m3<br>
<br>SELECT THE WEIGHT OF YOUR PACKAGE:<br>
<input type="radio" name="weight" value="100"> from 0 to 100 Kg<br>
<input type="radio" name="weight" value="200"> from 100 to 200 Kg<br>
<input type="radio" name="weight" value="300"> from 200 to 300 Kg<br>
<input type=submit>
</form>
<?php //(continue where we left off)
}
?>

// starts a line comment. so does PERL's #
\n is a line break which is ignored by HTML but useful for viewing source.
\" in a double-quoted string simply comes out as a " character. echo and
print both send strings as output to the browser. I could have shortened my
typing and did a $wt=$_GET['weight']; and used $wt everywhere, same with the
volume. I don't think I have to put quotes around the numbers - if I
remember right, PHP converts numbers in strings into numbers automatically.
if you are not sure, use the triple-equals (I did) instread of double-equals
for comparing.
If you want to take a look at PHP,

"Marta" <(E-Mail Removed)> wrote in message
news:cnm6na$obe$(E-Mail Removed)...
> Hi all!
>
> I would to study a web programming language to create a script that, given
> the following
> input page (input.htm) where the user select the weight and volume of a
> package to be shipped, returns the prices of various couriers ("yellow",
> "blue" and "black").
> Is Perl my best choice? or PHP? ASP is much more complicated?
>
> ~~~ input page input.htm:
>
> <form method="GET" action="output.php" name="input">
>
> SELECT THE VOLUME OF YOUR PACKAGE:
>
> <input type="radio" name="volume" value="1"> from 0 to 1 m3
> <input type="radio" name="volume" value="2"> from 1 to 2 m3
> <input type="radio" name="volume" value="3"> from 2 to 3 m3
>
> <br>SELECT THE WEIGHT OF YOUR PACKAGE:
>
> <input type="radio" name="weight" value="100"> from 0 to 100 Kg
> <input type="radio" name="weight" value="200"> from 100 to 200 Kg
> <input type="radio" name="weight" value="300"> from 200 to 300 Kg
>
> </form>
>
> ~~~ istructions to be integrated in the "output.php" script:
>
> Courier "yellow" - for volume 1, 2 and 3:
> if weight=100 then rate=600
> if weight=200 then rate=900
> if weight=300 then rate=1200
>
> Courier "blue" - for volume 1 and 2:
> if weight=100 then rate=400
> if weight=200 then rate=700
>
> Courier "black" - for volume 2 and 3:
> if weight=100 then rate=800
> if weight=200 then rate=1100
> if weight=300 then rate=1500
>
>
> ~~~ sample request and result:
>
> Example A) With the user input:
> volume=2
> weight=300
>
> output.php must generate this result:
> courier "yellow" = 1200
> courier "black" = 1500
>
>
> Example B) With the user input:
> volume=1
> weight=100
>
> output.php must generate this result:
> courier "yellow" = 600
> courier "blue" = 400
>
>
>



 
Reply With Quote
 
 
 
 
Gunnar Hjalmarsson
Guest
Posts: n/a
 
      01-14-2006
Jim Michaels wrote:
> I know this is a PERL group, but having worked with PERL and PHP, I've
> chosen to work with PHP for web apps.


Not a bad choice; thanks for letting us know. If you are happy, we are
happy.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      01-14-2006
Jim Michaels <(E-Mail Removed)> wrote:

> I know this is a PERL group,



Then you know incorrectly.

This is a Perl group.


--
Tad McClellan SGML consulting
http://www.velocityreviews.com/forums/(E-Mail Removed) Perl programming
Fort Worth, Texas
 
Reply With Quote
 
Jim Michaels
Guest
Posts: n/a
 
      01-15-2006
I stand corrected. it's been a while. I just looked at the official Perl
book's title. I used to write all my GUIs in Tcl/TK (still do), system
utilities in C++ and Perl. But I'm no longer maintaining a server.
Actually, I did write a GUI in Perl because it had Tk available (a bit more
cumbersome under Perl than Tcl).

If you do try Tk, I suggest having a Tcl/Tk book handy as a reference on the
widgets and how they work, as the documentation that comes with the Perl
module isn't sufficient. And you'll need lots of time experimenting if
you're using a newer widget like heirarchy (the name was something like
that).

"Tad McClellan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Jim Michaels <(E-Mail Removed)> wrote:
>
>> I know this is a PERL group,

>
>
> Then you know incorrectly.
>
> This is a Perl group.
>
>
> --
> Tad McClellan SGML consulting
> (E-Mail Removed) Perl programming
> Fort Worth, Texas



 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      01-15-2006
Jim Michaels wrote:
> If you do try Tk, I suggest having a Tcl/Tk book handy as a reference on the
> widgets and how they work, as the documentation that comes with the Perl
> module isn't sufficient.


Uhm. No. If you try to to *Tcl/Tk*, you should have a Tcl/Tk book
handy. If you try to do *Perl/Tk*, you should have a *Perl/Tk* book
handy.

http://www.oreilly.com/catalog/mastperltk/

If you're programming in C, do you want a C book or a C++ book? Why
would you want a book for a language that's only tangentally related to
the language you're using?

Paul Lalli

 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Announcing CVExp: A library for making linear programming easier David Baird Python 0 02-18-2009 06:13 AM
I find the perl syntax easier than python flifus@gmail.com Perl Misc 12 05-03-2007 09:45 PM
easier way to layout a web form Steve Richter ASP .Net 2 07-01-2005 03:46 PM
Has to be an easier way? (gateway issues) Captain Cisco 13 08-28-2004 12:30 AM
Hash of Structs in a Package, is there an easier way? Norman Ackroyd Perl 1 07-28-2004 11:54 AM



Advertisments