Easier web programming language: PERL or PHP?

Discussion in 'Perl Misc' started by Marta, Nov 20, 2004.

  1. Marta

    Marta Guest

    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
    Marta, Nov 20, 2004
    #1
    1. Advertising

  2. Marta wrote:
    > Is Perl my best choice? or PHP? ASP is much more complicated?


    Is a Ford better then a Chevy? Or is a Mercedes more complicated?

    Pick whatever you feel most comfortable with.
    For a simple problem like you described above the programming language
    really doesn't matter and chances are you will be most productive in
    whatever language you feel most comfortable.

    jue
    Jürgen Exner, Nov 20, 2004
    #2
    1. Advertising

  3. [ newsgroups trimmed, I don't do the alt.* wasteland, only this wasteland ]


    Marta <> wrote:

    > I would to study a web programming language



    Then you are in the wrong place because Perl (not PERL) is
    not a web programming language (but PHP is).

    Perl is a general purpose programming language, it works great
    for web stuff and for lots of other stuff as well.

    PHP works great for web stuff.


    > Is Perl my best choice?



    Yes, if you ask in a Perl newsgroup.


    > or PHP?



    Yes, if you ask in a PHP newsgroup.


    > ASP is much more complicated?



    Proprietary stuff sucks big ones.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Nov 20, 2004
    #3
  4. Marta

    Alan Mead Guest

    On Sat, 20 Nov 2004 01:51:22 +0100, Marta wrote:

    > I would to study a web programming language to create a script that,
    > given


    Perl would be the best choice here because it was designed with postage
    and packaging in mind. (That's what the 'P' in Perl stands for).

    Here are a couple websites to get you started:

    http://stein.cshl.org/WWW/software/CGI/
    http://stein.cshl.org/WWW/software/CGI/examples/

    Lincoln Stein (CGI.pm author) has an easy-to-read book and I recommend it
    highly. The book discusses the examples from the second link.

    -Alan
    Alan Mead, Nov 20, 2004
    #4
  5. On Fri, 19 Nov 2004 23:08:47 -0600, Alan Mead <>
    wrote:

    >Perl would be the best choice here because it was designed with postage
    >and packaging in mind. (That's what the 'P' in Perl stands for).

    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    Huh?!? Where did you hear that?


    Michele
    --
    {$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
    (($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
    ..'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
    256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
    Michele Dondi, Nov 20, 2004
    #5
  6. On Fri, 19 Nov 2004, Tad McClellan wrote:

    > [ newsgroups trimmed, I don't do the alt.* wasteland, only this
    > wasteland ]


    giggle

    > > ASP is much more complicated?

    >
    > Proprietary stuff sucks big ones.


    No dispute on that. But I would suggest that you missed an important
    issue here. ASP isn't a programming language (not even a web
    programming language, whatever that might be exactly). It's more in
    the nature of an interface specification. The programming language to
    which it interfaces might often be VB, but it doesn't have to be.

    So, in terms of its nature, ASP should be compared with CGI, or
    with the Apache API, not with a programming language.

    Perhaps one could mention http://www.apache-asp.org/ - without
    however, particularly recommending it to someone who's not yet
    in a position to make an informed choice.
    Alan J. Flavell, Nov 20, 2004
    #6
  7. On Fri, 19 Nov 2004, Alan Mead wrote:

    > Perl would be the best choice here because it was designed with postage
    > and packaging in mind. (That's what the 'P' in Perl stands for).


    Whose leg are you pulling?
    Alan J. Flavell, Nov 20, 2004
    #7
  8. Marta

    Clyde Ingram Guest

    Alan,

    "Alan Mead" <> wrote in message
    news:p...
    > Perl would be the best choice here because it was designed with postage
    > and packaging in mind. (That's what the 'P' in Perl stands for).


    You must be mistaken: Perl has only one "P", so offers either Postage or
    Packaging, but not both.
    In this respect, Perl, regrettably, offer no more and no less than than ASP.

    It is well known that, PHP, with two "P"s, offers both Postage and
    Packaging.

    By the same token, C offers delivery by Courier, Java suffers from Junk
    mail, and VBS provides a Very Bad Service all round.

    > Here are a couple websites to get you started:
    >
    > http://stein.cshl.org/WWW/software/CGI/
    > http://stein.cshl.org/WWW/software/CGI/examples/
    >
    > Lincoln Stein (CGI.pm author) has an easy-to-read book and I recommend it
    > highly. The book discusses the examples from the second link.


    Agreed. A brilliant book by a great writer, but rather overdue a reprint.
    Fortunately, the first web page you quote, at "Version 3.05, 04/12/2004, L.
    Stein", goes a long way to updating the book.

    Regards,
    Clyde
    Clyde Ingram, Nov 20, 2004
    #8
  9. Marta

    Alan Mead Guest

    On Sat, 20 Nov 2004 20:09:42 +0000, Clyde Ingram wrote:

    > You must be mistaken: Perl has only one "P", so offers either Postage or
    > Packaging, but not both.
    > In this respect, Perl, regrettably, offer no more and no less than than ASP.
    >
    > It is well known that, PHP, with two "P"s, offers both Postage and
    > Packaging.


    I stand corrected :)

    -Alan
    Alan Mead, Nov 21, 2004
    #9
  10. Marta

    T. Jansma Guest

    Alan Mead <> wrote in message news:<>...
    > > I would to study a web programming language to create a script that,
    > > given

    >
    > Perl would be the best choice here because it was designed with postage
    > and packaging in mind. (That's what the 'P' in Perl stands for).


    Oh, haha, no, crazy coot... PHP is best suited for this, PHP stands
    for:
    Package Handling & Pricing

    Imagine that, a whole programming language designed exactly for this
    problem, wow! :)

    CU!
    Tim.
    T. Jansma, Nov 21, 2004
    #10
  11. Marta

    Jim Michaels Guest

    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" <> wrote in message
    news:cnm6na$obe$...
    > 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
    >
    >
    >
    Jim Michaels, Jan 14, 2006
    #11
  12. 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
    Gunnar Hjalmarsson, Jan 14, 2006
    #12
  13. Jim Michaels <> wrote:

    > I know this is a PERL group,



    Then you know incorrectly.

    This is a Perl group.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 14, 2006
    #13
  14. Marta

    Jim Michaels Guest

    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" <> wrote in message
    news:...
    > Jim Michaels <> wrote:
    >
    >> I know this is a PERL group,

    >
    >
    > Then you know incorrectly.
    >
    > This is a Perl group.
    >
    >
    > --
    > Tad McClellan SGML consulting
    > Perl programming
    > Fort Worth, Texas
    Jim Michaels, Jan 15, 2006
    #14
  15. Marta

    Paul Lalli Guest

    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
    Paul Lalli, Jan 15, 2006
    #15
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Greg
    Replies:
    5
    Views:
    371
  2. David Baird
    Replies:
    0
    Views:
    284
    David Baird
    Feb 18, 2009
  3. Rajive Narain
    Replies:
    0
    Views:
    1,702
    Rajive Narain
    Sep 18, 2009
  4. Ignoramus6539
    Replies:
    2
    Views:
    204
    Colin McKinnon
    Aug 30, 2006
  5. Replies:
    12
    Views:
    199
    Michele Dondi
    May 3, 2007
Loading...

Share This Page