[26814] in Perl-Users-Digest
Perl-Users Digest, Issue: 8851 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 14 18:05:27 2006
Date: Sat, 14 Jan 2006 15:05:04 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Sat, 14 Jan 2006 Volume: 10 Number: 8851
Today's topics:
Re: Easier web programming language: PERL or PHP? <jmichae3@yahoo.com>
Re: Easier web programming language: PERL or PHP? <noreply@gunnar.cc>
Re: form fields <nospam@home.com>
mechanize follow_link () on an image <nospam@home.com>
Re: mechanize follow_link () on an image <mark.clementsREMOVETHIS@wanadoo.fr>
Re: mechanize follow_link () on an image <nospam@home.com>
Re: mechanize follow_link () on an image <mark.clementsREMOVETHIS@wanadoo.fr>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 14 Jan 2006 01:57:32 -0800
From: "Jim Michaels" <jmichae3@yahoo.com>
Subject: Re: Easier web programming language: PERL or PHP?
Message-Id: <UoudnYTfM96NUFXenZ2dnUVZ_v2dnZ2d@comcast.com>
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 "yellow"
rate=600<br>\n"; }
if ($_GET['weight']===200) { echo "courier "yellow"
rate=900<br>\n"; }
if ($_GET['weight']===300) { echo "courier "yellow"
rate=1200<br>\n"; }
//Courier "blue" - for volume 1 and 2:
if ($_GET['volume']===1 || $_GET['volume']===2) {
if ($_GET['weight']===100) { echo "courier "blue"
rate=400<br>\n"; }
if ($_GET['weight']===200) { echo "courier "blue"
rate=700<br>\n"; }
}
//Courier "black" - for volume 2 and 3:
if ($_GET['volume']===2 || $_GET['volume']===3) {
if ($_GET['weight']===100) { echo "courier "black"
rate=800<br>\n"; }
if ($_GET['weight']===200) { echo "courier "black"
rate=1100<br>\n"; }
if ($_GET['weight']===300) { echo "courier "black"
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" <marta@mariapia.com> wrote in message
news:cnm6na$obe$2@lacerta.tiscalinet.it...
> 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
>
>
>
------------------------------
Date: Sat, 14 Jan 2006 11:11:34 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Easier web programming language: PERL or PHP?
Message-Id: <42s12oF1krdo0U1@individual.net>
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
------------------------------
Date: Sat, 14 Jan 2006 15:42:49 GMT
From: "Nospam" <nospam@home.com>
Subject: Re: form fields
Message-Id: <ZZ8yf.68286$Cj5.40266@newsfe6-win.ntli.net>
what would I need for the submit button on the form
would something like
$mech->follow_link(submit);
or $mech->submit(Submit);
or $mech->click(Submit);
be appropriate seeing it is a submit image?
all the checks state the message was successfully sent but nothing has been
sent, I am wondering if I need a cookie somewhere
------------------------------
Date: Sat, 14 Jan 2006 20:55:59 GMT
From: "Nospam" <nospam@home.com>
Subject: mechanize follow_link () on an image
Message-Id: <zzdyf.53804$Dg6.24832@newsfe3-gui.ntli.net>
I am wondering how I can follow the postreply link on this url:
http://www.warservers.com/f/viewtopic~t~19029.htm
according to mechanize
follow_link(text_regex => qr/Reply to topic/i);
or
follow_link(url_regex=> qr/Reply to topic/i);
or
follow_link(tag_regex => qr/Reply to topic/i);
should all work, but unfortunately they don't, I don't know if it is my
version of mechanize I know the latest from uwinnipeg is version 1.14 and I
have so far been unable to set repository uwinnepeg urlofuwinnipeg I am on
activeperl 5.8X
------------------------------
Date: Sat, 14 Jan 2006 22:08:25 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: mechanize follow_link () on an image
Message-Id: <43c9684c$0$29206$8fcfb975@news.wanadoo.fr>
Nospam wrote:
> I am wondering how I can follow the postreply link on this url:
> http://www.warservers.com/f/viewtopic~t~19029.htm
>
> according to mechanize
>
> follow_link(text_regex => qr/Reply to topic/i);
>
> or
>
> follow_link(url_regex=> qr/Reply to topic/i);
>
> or
> follow_link(tag_regex => qr/Reply to topic/i);
>
> should all work, but unfortunately they don't, I don't know if it is my
> version of mechanize I know the latest from uwinnipeg is version 1.14 and I
> have so far been unable to set repository uwinnepeg urlofuwinnipeg I am on
> activeperl 5.8X
>
>
According to the docs, with follow_link:
You specify the match to be found using the same parms that
"find_link()" uses.
With find_link, one can specify
$mech->find_link( name => "blahblah" );
"View page info" in Firefox tells me that the relevant link has a name
of "Reply to topic". So
follow_link( name => "Reply to topic")
may be worth a shot.
View source reveals some oddness, but:
the url is
http://www.warservers.com/f/posting~mode~reply~t~19029.htm
(with some spaces on the end)
so that will never match "Reply to topic". There is no text (it's an
image), so text_regex will never match. The tag is the html tag is "a"
or "img", so tag_regex will never match for you either.
If searching on name doesn't work, I'd suggest something like
url_regex => "newtopic"
Mark
------------------------------
Date: Sat, 14 Jan 2006 22:30:45 GMT
From: "Nospam" <nospam@home.com>
Subject: Re: mechanize follow_link () on an image
Message-Id: <pYeyf.38858$yu.29778@newsfe6-gui.ntli.net>
tried your suggestions, none of them work unfortunately
I am wondering if i used $mech->find_link( tag_regex=>"newtopic.gif");
then followed the contents:
my $regex2 = find_link( tag_regex=>"newtopic.gif");
follow_link($regex2);
if it would make any difference?
------------------------------
Date: Sat, 14 Jan 2006 23:59:08 +0100
From: Mark Clements <mark.clementsREMOVETHIS@wanadoo.fr>
Subject: Re: mechanize follow_link () on an image
Message-Id: <43c9823f$0$20171$8fcfb975@news.wanadoo.fr>
Nospam wrote:
> tried your suggestions, none of them work unfortunately
>
> I am wondering if i used $mech->find_link( tag_regex=>"newtopic.gif");
>
> then followed the contents:
> my $regex2 = find_link( tag_regex=>"newtopic.gif");
>
> follow_link($regex2);
>
> if it would make any difference?
>
>
try this:
use strict;
use warnings;
use Data::Dumper;
use WWW::Mechanize;
use constant START => "http://www.warservers.com/f/viewtopic~t~19029.htm";
my $mech = WWW::Mechanize->new();
$mech->get( START );
print $mech->uri."\n";
$mech->follow_link( url_regex => qr(posting~mode~reply));
print $mech->uri."\n";
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8851
***************************************