[23244] in Perl-Users-Digest
Perl-Users Digest, Issue: 5465 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 8 18:06:02 2003
Date: Mon, 8 Sep 2003 15:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 8 Sep 2003 Volume: 10 Number: 5465
Today's topics:
Re: "Surrogate infinity" in Perl? <krahnj@acm.org>
Re: "Surrogate infinity" in Perl? <jill_krugman@yahoo.com>
Re: "Surrogate infinity" in Perl? <minceme@start.no>
Re: DBI Output Help (Tom)
Dynamically Creating Variables (Tom)
Re: Dynamically Creating Variables <tore@aursand.no>
Re: Dynamically Creating Variables <uri@stemsystems.com>
Re: Dynamically Creating Variables <usenet@expires12.2003.tinita.de>
Re: Dynamically Creating Variables (Tad McClellan)
Re: emulating @+ and @- <tassilo.parseval@rwth-aachen.de>
Re: Help configuring Perl with Apache 2 (Tad McClellan)
Re: how to do a simple check <usenet@expires12.2003.tinita.de>
Re: Looping scalar and regex'ing it <michael.p.broida@boeing.com>
Perl Arguements (Paul)
Re: Perl Arguements <usenet@expires12.2003.tinita.de>
Re: Perl Arguements <postmaster@castleamber.com>
Re: Perl Arguements <michael.p.broida@boeing.com>
Re: perl simple cms <andrew@NOSPAM_andicrook.demon.co.uk>
Re: Problem with simple contact script. (Tom)
Re: Problem with simple contact script. <postmaster@castleamber.com>
Re: Problem with simple contact script. <noreply@gunnar.cc>
qr// question <mpapec@yahoo.com>
Re: qr// question <krahnj@acm.org>
Quotes and circular references (JR)
Re: simple regex problem <noreply@gunnar.cc>
Tk800.024 and Perl 5.8.1-RC4 <twhu@lucent.com>
Re: Tk800.024 and Perl 5.8.1-RC4 <twhu@lucent.com>
Re: Tk800.024 and Perl 5.8.1-RC4 <twhu@lucent.com>
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 08 Sep 2003 18:16:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: "Surrogate infinity" in Perl?
Message-Id: <3F5CC784.D3675FF5@acm.org>
J Krugman wrote:
>
> In C, for example, one can use certain predefined constants as
> "surrogate infinity", meaning that no number (of the appropriate
> type) handled by a C program will ever be greater than the appropriate
> constant. For example:
>
> int min_val;
> ...
>
> min_val = INT_MAX; /* INT_MAX used as a surrogate infinity */
> for(i = 0; i < ITER; ++i) {
> if ( min_val > arr[i] ) {
> min_val = arr[i];
> }
> }
>
> Is there a similar facility in Perl?
use POSIX;
my $min_val = INT_MAX;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Mon, 8 Sep 2003 18:34:49 +0000 (UTC)
From: J Krugman <jill_krugman@yahoo.com>
Subject: Re: "Surrogate infinity" in Perl?
Message-Id: <bjii49$6c5$2@reader2.panix.com>
In <3F5CC784.D3675FF5@acm.org> "John W. Krahn" <krahnj@acm.org> writes:
>use POSIX;
>my $min_val = INT_MAX;
That's the ticket. Thanks!
-Jill
------------------------------
Date: Mon, 8 Sep 2003 18:57:50 +0000 (UTC)
From: Vlad Tepes <minceme@start.no>
Subject: Re: "Surrogate infinity" in Perl?
Message-Id: <bjijfd$f5v$1@troll.powertech.no>
J Krugman <jill_krugman@yahoo.com> wrote:
I'm don't know much C, but I suspect your wanting to set INT_MAX comes
from a desire to restrict yourself. Bondage could be implemented by
tie()ing your variables. I'm not usually into that sort of thing,
but I had to check it out:
#!/usr/bin/perl
use strict;
use warnings;
package Bondage;
require Tie::Scalar;
our @ISA = qw( Tie::StdScalar );
my %MAX;
sub TIESCALAR {
my $class = shift;
my $value;
my $self = bless \$value, $class;
$MAX{$self} = shift;
$self;
}
sub STORE {
my $self = shift;
my $value = shift;
if ( $value > $MAX{$self} ) {
die "Overflow: $MAX{$self} < $value"
}
$$self = $value;
$value;
}
package main;
tie my $i, "Bondage", 5; # Overflow if $i > 5
printf "i = %d\n", $i = $_ for (1..7);
--
Vlad
------------------------------
Date: 8 Sep 2003 11:08:04 -0700
From: ompers@hotmail.com (Tom)
Subject: Re: DBI Output Help
Message-Id: <f4144fab.0309081008.47915f97@posting.google.com>
tom@ztml.com (Tom) wrote in message news:<59b4279a.0309070513.344d894e@posting.google.com>...
> ompers@hotmail.com (Tom) wrote in message news:<f4144fab.0309061156.77e83ec1@posting.google.com>...
> > Hello.
> >
> > I am learning Perl and have decided to create a web page that has
> > dropdowns populated by a postgreSQL DB. I've been able to do this and
> > the page looks fine but the code is awful. A chunk of the code is
> > posted below; can anyone suggest a way to clean this up and make it
> > more efficient? Namely, I am trying to consolidate the actual
> > population of the <SELECT> into one loop, and figure out a way to get
> > rid of the ugly "$i < scalar(@array)" line.
> >
> > This all works, but I'm still learning Perl and haven't figured out
> > how to make it work good!
> >
> > Thanks,
> > Tom
> >
> > CODE BELOW:
> > ===========
> >
> >
> > #!/opt/perl/bin/perl -wT
> > use DBI;
> > use CGI;
> > use CGI::Carp qw(fatalsToBrowser);
> >
> > my $q = new CGI;
> >
> > my $dbh = DBI->connect( "dbi:Pg:dbname=web" ) || die;
> > my @a = ('groupdescription','groups');
> > my @b = ('role','servers_role');
> > my $sth1 = $dbh->prepare("Select $a[0] from $a[1] order by $a[0]");
> > my $sth2 = $dbh->prepare("Select $b[0] from $b[1] order by $b[0]");
> >
> > $sth1->execute;
> > $sth2->execute;
> >
> > print $q->header,
> > $q->start_html,
> > $q->startform,
> > "<table><Tr><td>$a[0]</td>",
> > "<td><Select name=\"$a[0]\">";
> >
> > while( @row1 = $sth1->fetchrow ) {
> > for( $i = 0; $i < scalar(@row1); $i++ ) {
> > print "<option value=\"$row1[$i]\">$row1[$i]";
> > }
> > }
> > print "</Select></td></Tr>",
> > "<Tr><td>$b[0]</td>",
> > "<td><Select name=\"$b[0]\">";
> >
> > while( @row2 = $sth2->fetchrow ) {
> > for( $i = 0; $i < scalar(@row2); $i++ ) {
> > print "<option value=\"$row2[$i]\">$row2[$i]";
> > }
> > }
> > print "</Select></td></Tr></table></body></html>";
>
> Try this...
>
> my ($selectrow1,$selectrow2) =
> ("<table><Tr><td>$a[0]</td><td><select name='$a[0]'>",
> "<tr><td>$b[0]</td><td><select name='$b[0]'>");
>
> while( (@row1 = $sth1->fetchrow ) or (@row2 = $sth2->fetchrow) )
> {
> for (@row1) { $selectrow1 .= "<option value='$_\'>$_</option>\n" }
> for (@row2) { $selectrow2 .= "<option value='$_\'>$_</option>\n" }
> }
> print "$selectrow1</Select></td></Tr>\n$selectrow2</Select></td></Tr></table></body></html>";
>
>
> Tom
> ztml.com
Thanks a lot for the help guys! I ended up with a solution very
similar to your suggestions:
while( my @row = $sth1->fetchrow ) {
for(@row) { print "<option value='$_'>$_</option>" }
}
Works great. I also am using 'fetchrow_array' to retrieve single
results; and yes, I put use strict; back into place ;-).
Thanks again,
Tom
------------------------------
Date: 8 Sep 2003 11:25:25 -0700
From: ompers@hotmail.com (Tom)
Subject: Dynamically Creating Variables
Message-Id: <f4144fab.0309081025.32de0549@posting.google.com>
Hello,
I have a chunk of code that executes six statement handles from the
DBI module as follows:
$sth1->execute;
$sth2->execute;
$sth3->execute;
$sth4->execute;
$sth5->execute;
$sth6->execute;
The code runs fine but is it possible to run that through a loop using
Perl? I.e. something like:
for( my $i = 1; $i < 7; $i++ ) {
$sth${i}->execute;
}
The above doesn't work, was just my attempt. I've done quite a bit of
this type of looping via shell but am not sure of the correct syntax
for Perl.
Thanks for any help.
Tom
------------------------------
Date: Mon, 08 Sep 2003 20:31:19 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: Dynamically Creating Variables
Message-Id: <pan.2003.09.08.18.31.14.717916@aursand.no>
On Mon, 08 Sep 2003 11:25:25 -0700, Tom wrote:
> [...] is it possible to run that through a loop using Perl? I.e.
> something like:
>
> for( my $i = 1; $i < 7; $i++ ) {
> $sth${i}->execute;
> }
You don't want to do that. Quote from 'perldoc';
"Beginners often think they want to have a variable contain
the name of a variable.
[...]
This works sometimes, but it is a very bad idea for two
reasons."
Read through 'perldoc -q variable' for more information about this
specific topic.
--
Tore Aursand <tore@extend.no>
"Whenever I see an old lady slip and fall on a wet sidewalk, my first
instinct is to laugh. But then I think, what if I was an ant, and she
fell on me. Then it wouldn't seem quite so funny." -- Jack Handey
------------------------------
Date: Mon, 08 Sep 2003 18:31:31 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Dynamically Creating Variables
Message-Id: <x73cf7jfng.fsf@mail.sysarch.com>
>>>>> "T" == Tom <ompers@hotmail.com> writes:
T> for( my $i = 1; $i < 7; $i++ ) {
T> $sth${i}->execute;
T> }
use an array. you're falling under the evil spell of symrefs and you
don't want to go there.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
Damian Conway Class in Boston - Sept 2003 -- http://www.stemsystems.com/class
------------------------------
Date: 8 Sep 2003 21:34:41 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: Dynamically Creating Variables
Message-Id: <bjislh$ivcqu$2@ID-24002.news.uni-berlin.de>
Tom wrote:
> I have a chunk of code that executes six statement handles from the
> DBI module as follows:
> $sth1->execute;
> $sth2->execute;
> $sth3->execute;
> $sth4->execute;
> $sth5->execute;
> $sth6->execute;
> The code runs fine but is it possible to run that through a loop using
> Perl?
sure.
for ($sth1, $sth2, $sth3, $sth4, $sth5, $sth6) {
$_->execute;
}
you should use an array, as it was suggested already.
it will cost you time to rewrite the code, but in the end
it will save you much more time.
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -
------------------------------
Date: Mon, 8 Sep 2003 14:52:53 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Dynamically Creating Variables
Message-Id: <slrnblpngl.j6o.tadmc@magna.augustmail.com>
Tom <ompers@hotmail.com> wrote:
> I have a chunk of code that executes six statement handles from the
> DBI module as follows:
>
> $sth1->execute;
> $sth2->execute;
> $sth3->execute;
> $sth4->execute;
> $sth5->execute;
> $sth6->execute;
>
> The code runs fine but is it possible to run that through a loop using
> Perl?
(untested)
foreach my $sth ( $sth1, $sth2, $sth3, $sth4, $sth5, $sth6 ) {
$sth->execute;
}
or
$_->execute for $sth1, $sth2, $sth3, $sth4, $sth5, $sth6;
I thought you were going to ask something about dynamically
creating variables.
Did you leave the question corresponding to your Subject out of your
article by mistake or something?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Sep 2003 19:24:59 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: emulating @+ and @-
Message-Id: <bjil2b$e07$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Ilya Zakharevich:
><tassilo.parseval@post.rwth-aachen.de>], who wrote in article <bjhua3$kkv$1@nets3.rz.RWTH-Aachen.DE>:
>> That's smart. I think that this will make it easy to solve my problem.
>> 'struct regexp' (among others) holds
>>
>> U32 nparens; /* number of parentheses */
>> U32 lastparen; /* last paren matched */
>> U32 lastcloseparen; /* last paren matched */
>>
>> One of those (or even all of them) is probably what I am looking for.
>
> Keep in mind that struct regexp is used for *two* purposes (I did not
> have time to clean this when working with REx engine): it keeps a part
> of the state during the match process, and it keeps the info used for
> $<digit> etc *after* the match. Be sure to use only the entries
> mentioned in mg.c.
I eventually went for lastparen which seems to work very well. PM_GETRE
had to be added, and that was all. My little XSUB now reads as
int
num_submatches ()
CODE:
#ifndef PM_GETRE
# define PM_GETRE(o) ((o)->op_pmregexp)
#endif
RETVAL = PM_GETRE(PL_curpm)->lastparen;
OUTPUT:
RETVAL
After a wild and ambitious attempt of adding the whole of @+ in @- to
5.00503 failed (naturally, it didn't yet know of about 'D' magic), I can
still implement them as tied arrays. That way I wouldn't need to change
my Perl code.
Ilya, thanks for the invaluable pointers to the relevant bits of the
Perl source. Normally, regexes on the source level really scare me, but
here it was surprisingly not hard at all.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 8 Sep 2003 14:46:12 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Help configuring Perl with Apache 2
Message-Id: <slrnblpn44.j6o.tadmc@magna.augustmail.com>
John Bokma <postmaster@castleamber.com> wrote:
> Tad McClellan wrote:
>> Cyde Weys <cyde@umd.edu> wrote:
>
>>>I just asked what was the
>>>point of saying *plonk*
>>
>> So that the lurkers will know what price they may pay should
>> they ever feel the urge to post their server setup questions here.
>
> A *plonk* is as off topic as the original post and hence adds to the noise.
For one thread's worth, while perhaps preventing many more such threads.
> Just ignore off topic posts and don't reply in any way.
No thank you.
If you litter in the park, I will ask you to not do that anymore.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 8 Sep 2003 21:43:21 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: how to do a simple check
Message-Id: <bjit5p$ivcqu$3@ID-24002.news.uni-berlin.de>
JS wrote:
> This worked:
> usage() if ! $ARGV[0] ;
only if the file isn't called "0"
=)
regards, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -
------------------------------
Date: Mon, 8 Sep 2003 21:19:44 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Looping scalar and regex'ing it
Message-Id: <3F5CF270.BC7458F1@boeing.com>
Tad McClellan wrote:
>
> Michael P. Broida <michael.p.broida@boeing.com> wrote:
> > Moltar wrote:
> >>
> >> Hmm.. I was actually thinking of looping. Because I need to do other stuff with it later.
>
> > You can use the "/g" on the string match in a loop with a scalar
> > result instead of an array. Each time you do the string match,
> ^^^^^^^^^^^^^^^^^^^
>
> ( instead of a _list_ )
Oops, yes. I need to be more precise. :)
> > it will remember the previous point and work from there.
>
> and the pos() function will tell you where it left off.
I didn't know that. Good info.
> > NOTE: Doing other regex work inside the loop will (I'm pretty sure)
> > screw it up: it will lose its place in $string. Or I could be
> > wrong on that, too.
>
> You can do other pattern matching against _other_ strings with
> no problem.
>
> If you do mattern matching with $string though, then the match
> position is _supposed to_ move.
>
> The position info resides with the string being matched against,
> rather than with the pattern to be matched.
>
> You can use the \G anchor in all of the patterns that match
> against $string to force it to start off where the last
> one left off.
That's what I wasn't straight on. I didn't know the
"scope" of the /g positioning info. Thanks for
clearing that up. Now I'll be able to use /g
without problems. :)
Mike
------------------------------
Date: 8 Sep 2003 13:38:15 -0700
From: pecymanski@yahoo.com (Paul)
Subject: Perl Arguements
Message-Id: <f65ace75.0309081238.537e1cce@posting.google.com>
I am having difficulty in getting the Perl Interpretor to recognize
arguements submitted with a perl script. For example,I have a simple
perl script like this called temp.pl
print "ARGV0 : $ARGV[0]\n";
print "ARGV1 : $ARGV[1]\n";
print "ARGV2 : $ARGV[2]\n";
If I run the script as 'temp.pl A B C',I get the following output:
ARGV0 :
ARGV1 :
ARGV2 :
If I run the script as 'perl temp.pl A B C', the arguements are then
recognized and I get the following output:
ARGV0 : A
ARGV1 : B
ARGV2 : C
I do not understand why the difference, the perl scripts is running in
both cases, but in the first case no arguements seem to be recognized.
Thanks for any help, Paul
------------------------------
Date: 8 Sep 2003 21:27:35 GMT
From: Tina Mueller <usenet@expires12.2003.tinita.de>
Subject: Re: Perl Arguements
Message-Id: <bjis87$ivcqu$1@ID-24002.news.uni-berlin.de>
Paul wrote:
> I am having difficulty in getting the Perl Interpretor to recognize
> arguements submitted with a perl script. For example,I have a simple
> perl script like this called temp.pl
> print "ARGV0 : $ARGV[0]\n";
> print "ARGV1 : $ARGV[1]\n";
> print "ARGV2 : $ARGV[2]\n";
> If I run the script as 'temp.pl A B C',I get the following output:
> ARGV0 :
> ARGV1 :
> ARGV2 :
which operating sytem, which perl version?
> If I run the script as 'perl temp.pl A B C', the arguements are then
> recognized and I get the following output:
> ARGV0 : A
> ARGV1 : B
> ARGV2 : C
> I do not understand why the difference, the perl scripts is running in
> both cases, but in the first case no arguements seem to be recognized.
i don't understand the difference, either. for me it works, if
i call the script with ./temp.pl (if the rights are set correctly):
$ cat temp.pl
#!/usr/bin/perl -w
use strict;
print "ARGV0 : $ARGV[0]\n";
print "ARGV1 : $ARGV[1]\n";
print "ARGV2 : $ARGV[2]\n";
$ ls -l temp.pl
-rwxr--r-- 1 tina users 115 Sep 8 23:27 temp.pl
$ temp.pl A B C
bash: temp.pl: command not found
$ ./temp.pl A B C
ARGV0 : A
ARGV1 : B
ARGV2 : C
hth, tina
--
http://www.tinita.de/ \ enter__| |__the___ _ _ ___
http://Movies.tinita.de/ \ / _` / _ \/ _ \ '_(_-< of
http://www.perlquotes.de/ \ \ _,_\ __/\ __/_| /__/ perception
- the above mail address expires end of december 2003 -
------------------------------
Date: Mon, 08 Sep 2003 23:39:02 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Perl Arguements
Message-Id: <1063057247.132509@halkan.kabelfoon.nl>
Tina Mueller wrote:
> Paul wrote:
>
>>I am having difficulty in getting the Perl Interpretor to recognize
>>arguements submitted with a perl script. For example,I have a simple
>>perl script like this called temp.pl
>
>
>>print "ARGV0 : $ARGV[0]\n";
>>print "ARGV1 : $ARGV[1]\n";
>>print "ARGV2 : $ARGV[2]\n";
>
>
>>If I run the script as 'temp.pl A B C',I get the following output:
>>ARGV0 :
>>ARGV1 :
>>ARGV2 :
>
>
> which operating sytem, which perl version?
I suspected Windows but Win2K + cmd.exe:
D:\Snippets>perl arg.pl foo bar
foo
bar
D:\Snippets>arg.pl foo bar
foo
bar
D:\Snippets>type arg.pl
print join("\n", @ARGV), "\n";
D:\Snippets>perl -v
This is perl, v5.8.0 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)
[snip]
--
Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
virtual home: http://johnbokma.com/ ICQ: 218175426
John web site hints: http://johnbokma.com/websitedesign/
------------------------------
Date: Mon, 8 Sep 2003 21:33:48 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Perl Arguements
Message-Id: <3F5CF5BC.FB85B8E2@boeing.com>
Paul wrote:
>
> I am having difficulty in getting the Perl Interpretor to recognize
> arguements submitted with a perl script. For example,I have a simple
> perl script like this called temp.pl
>
> print "ARGV0 : $ARGV[0]\n";
> print "ARGV1 : $ARGV[1]\n";
> print "ARGV2 : $ARGV[2]\n";
>
> If I run the script as 'temp.pl A B C',I get the following output:
> ARGV0 :
> ARGV1 :
> ARGV2 :
>
> If I run the script as 'perl temp.pl A B C', the arguements are then
> recognized and I get the following output:
> ARGV0 : A
> ARGV1 : B
> ARGV2 : C
>
> I do not understand why the difference, the perl scripts is running in
> both cases, but in the first case no arguements seem to be recognized.
Do you have the "shebang" line at the beginning?
#!/usr/bin/perl
I'm thinking that if you DON'T have that line and you
run it without specifying "perl", then it's running
as commands to a shell (not executing "perl") which
-might- output what you see.
(Or maybe not; it's just a thought. I'm on Win32, so
can't test this theory.)
Mike
------------------------------
Date: Mon, 8 Sep 2003 20:33:48 +0100
From: "Andrew Crook" <andrew@NOSPAM_andicrook.demon.co.uk>
Subject: Re: perl simple cms
Message-Id: <bjilgq$csk$1$8302bc10@news.demon.co.uk>
can any of you recommend how I should go about storing the information in a
mysql database (database structure). Just need a few ideas to work from
many thanks
Andrew
"Andrew Crook" <andrew@NOSPAM_andicrook.demon.co.uk> wrote in message
news:bid6ac$3jd$1$8302bc10@news.demon.co.uk...
> I wish to make a perl cgi script that uses a html template and fills in
> data for the relevant markers and returns the page. Can any one recommend
> methods example code etc ?
>
> also wish to know about what to do with multi users using a cgi accessing
a
> CSV database or a single mysql account for example! ie what promblems
maybe
> caused by multipule writes on a file at the same time and how to overcome
> this.
>
> many thanks
>
> Andrew
>
>
>
------------------------------
Date: 8 Sep 2003 12:38:23 -0700
From: tom@ztml.com (Tom)
Subject: Re: Problem with simple contact script.
Message-Id: <59b4279a.0309081138.201a59ca@posting.google.com>
tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnblp0p4.ic0.tadmc@magna.augustmail.com>...
> Tom <tom@ztml.com> wrote:
> > .
> > .
> >
> > Try this...
> >
> > open(SM,">/usr/sbin/sendmail") or die $!;
>
>
> Do not try that.
>
> It does not invoke any programs, it attempts to open/create a file.
>
> It has nothing to do with your problem.
>
> This answer is from the Twilight Zone...
Sorry, I jump the gun. Perhaps you might want to try this...
#!/usr/bin/perl
use strict;
use Mail::sendMail;
use CGI qw(param);
print "Content-Type: text/html\n\n";
my $towhom = param("towhom");
my $name = param("name");
my $email = param("email");
my $comments = param("comments");
if($towhom eq "loanofficer")
{
$towhom = "loanofficer\@mortgage-pros.com";
}
elsif ($towhom eq "marketing")
{
$towhom="marketing\@mortgage-pros.com";
}
elsif ($towhom eq "broker")
{
$towhom="broker\@mortgage-pros.com";
}
my %mail = (
To => $towhom,
From => $email,
Subject => $name,
Message => $comments,
);
sendmail(%mail) or die $!;
print "Mail sent: $towhom";
-----------------------------
I hope this will meet your approval or otherwise, your next step is…
Tom
ztml.com
------------------------------
Date: Mon, 08 Sep 2003 21:56:30 +0200
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Problem with simple contact script.
Message-Id: <1063051095.373515@halkan.kabelfoon.nl>
Tom wrote:
> #!/usr/bin/perl
add -w and -T
> use strict;
> use Mail::sendMail;
> use CGI qw(param);
>
> print "Content-Type: text/html\n\n";
Don't output your headers yourself, use CGI for this.
> my $towhom = param("towhom");
> my $name = param("name");
> my $email = param("email");
> my $comments = param("comments");
>
> if($towhom eq "loanofficer")
> {
> $towhom = "loanofficer\@mortgage-pros.com";
> }
> elsif ($towhom eq "marketing")
> {
> $towhom="marketing\@mortgage-pros.com";
> }
> elsif ($towhom eq "broker")
> {
> $towhom="broker\@mortgage-pros.com";
> }
and what if towhom = "me@somewhere.invalid" ?
my %towhoms = (
loanofficer => 'loanofficer@mortgage-pros.com',
marketing => .....,
....
);
(if the domain is always the same this can be simplified, left as an
excercise to the reader :-) )
my $safe_towhom = $towhoms{$towhom};
unless (defined $safe_towhom) {
*REPORT ERROR!*
}
Since it is unexpected report an error, *don't* fix unexpected things.
> my %mail = (
> To => $towhom,
$safe_towhom...
[snip]
> print "Mail sent: $towhom";
$safe_towhom....
--
Kind regards, feel free to mail: mail(at)johnbokma.com (or reply)
virtual home: http://johnbokma.com/ ICQ: 218175426
John web site hints: http://johnbokma.com/websitedesign/
------------------------------
Date: Mon, 08 Sep 2003 22:13:48 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Problem with simple contact script.
Message-Id: <bjio08$j4nb2$1@ID-184292.news.uni-berlin.de>
Tom wrote:
>
> #!/usr/bin/perl
>
> use strict;
> use Mail::sendMail;
------------^---^
What is that? Do you mean
use Mail::Sendmail;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 08 Sep 2003 22:07:42 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: qr// question
Message-Id: <3knplvsoohivo1i5bjdaf4ksr38i8uloe8@4ax.com>
How can one know the difference between $arr[0] and $arr[1]?
eg.
my @arr = ('^match') x 2;
$_ = qr/$_/ for $arr[0];
I wouldn't want to do $_ = qr/$_/ twice on same regex (I guess it's time
consuming?)
--
Matija
------------------------------
Date: Mon, 08 Sep 2003 21:19:19 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: qr// question
Message-Id: <3F5CF25E.54918234@acm.org>
Matija Papec wrote:
>
> How can one know the difference between $arr[0] and $arr[1]?
Use 'eq' or '==' to compare them?
> eg.
> my @arr = ('^match') x 2;
In this instance the contents of $arr[0] and $arr[1] are exactly the
same.
> $_ = qr/$_/ for $arr[0];
>
> I wouldn't want to do $_ = qr/$_/ twice on same regex (I guess it's time
> consuming?)
What do you REALLY want to do?
John
--
use Perl;
program
fulfillment
------------------------------
Date: 8 Sep 2003 14:58:58 -0700
From: jrolandumuc@yahoo.com (JR)
Subject: Quotes and circular references
Message-Id: <b386d54b.0309081358.5d21b89@posting.google.com>
Hi. I came across an interesting situation today when quoting a
circular reference. For some reason, when I quoted the circular
reference $a, in the below script, and within the "h2" hash key for an
anonymous array, the output was different than when the circular
reference wasn't quoted (the output included HASH(0x1abf070) when the
circular reference was quoted, and the actual data when it wasn't).
I'm probably missing something very obvious here (it's the end of a
very long day). Does anyone know why this would be so?
Thanks much.
JR
------calling script-------
use lib 'OO_Practice';
use TRAVERSE_V2;
use Data::Dumper;
use strict;
use warnings;
use diagnostics;
## Circular reference
my $a = { name => 'joe', age => 31 };
$a->{circle_me_this} = $a;
my %hoa = (
h1 => [ "in_h1", [ "in_h1a" ], "out_h1" ],
h2 => [ "in_h2", [ "in_h2a" ], $a ],
h3 => [ "in_h3", [ "in_h3a" ], "out_h3" ],
);
my $sep = sub {print "-" x shift, "\n";};
print $a, "\n"; # prints HASH(0x1abf070)
print "$a\n"; # also prints HASH(0x1abf070) # quotes don't seem
# to matter here
$sep->(50);
my $object = TRAVERSE_V2->new(\\\\$a); # just data-good
&$sep(50);
print Dumper \\\\$a; # data and data structure-okay
&$sep(50);
$object = TRAVERSE_V2->new(\\\\%hoa); # prints: HASH(0x1abf070)
# $a is quoted; otherwise
# prints as expected
$sep->(50);
print Dumper \\\\%hoa; # prints: HASH(0x1abf070) when
# $a is quoted; otherwise
# prints as expected
------
------receiving class-------
use strict;
package TRAVERSE_V2;
sub new {
my (%r, $class);
my $self = shift;
my $class = ref($class) || $class;
while ($_ = shift(@_)) {
## beware circular references
## (handled by first condition of below clause)
$r{$_}>1 ? shift :
!ref($_) ? $r{$_}++ :
ref($_) eq 'REF' ? push @_, $$_ :
ref($_) eq 'HASH' ? push @_, %$_ :
ref($_) eq 'ARRAY' ? push @_, @$_ :
ref($_) eq 'SCALAR' ? push @_, $$_ :
ref($_) eq 'CODE' ? push @_, $_->() :
print "<<<Exception: $_>>>\n";
}
$self = [keys %r];
bless $self, $class; # create object
print "$_\n" for @$self; # print object
return $self; # return object
}
1;
----OUTPUT
HASH(0x1abf070)
HASH(0x1abf070)
--------------------------------------------------
joe
31
circle_me_this
name
age
--------------------------------------------------
$VAR1 = \\\\{
'circle_me_this' => ${${${${$VAR1}}}},
'age' => 31,
'name' => 'joe'
};
--------------------------------------------------
circle_me_this
out_h1
in_h1a
out_h3
h1
in_h2a
h2
name
h3
in_h3a
joe
in_h1
in_h2
in_h3
31
age
--------------------------------------------------
$VAR1 = \\\{
'h1' => [
'in_h1',
[
'in_h1a'
],
'out_h1'
],
'h2' => [
'in_h2',
[
'in_h2a'
],
{
'circle_me_this' =>
${${${$VAR1}}}->{'h2'}->[2],
'age' => 31,
'name' => 'joe'
}
],
'h3' => [
'in_h3',
[
'in_h3a'
],
'out_h3'
]
};
------------------------------
Date: Mon, 08 Sep 2003 20:07:43 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: simple regex problem
Message-Id: <bjigj7$jmk1v$1@ID-184292.news.uni-berlin.de>
John W. Krahn wrote:
> Gunnar Hjalmarsson wrote:
>>John W. Krahn wrote:
>>
>>>my ( $dept, $stats ) = unpack 'A24 A*', $_;
>>
>>That doesn't work for the E-Test line. How about:
>>
>> my ($dept, $stats) = /(.+[a-z])\s+(.*)/;
>
> Sorry, "doesn't work" is not enough information for me to fix the
> problem.
Didn't know it was your problem. ;-) Anyway, I tested your suggestion
with OP's original example data, i.e. without changing the number of
spaces:
while (<DATA>) {
my ( $dept, $stats ) = unpack 'A24 A*', $_;
print "$dept\n$stats\n\n";
}
__DATA__
E-Test 3 - 4 -
Health and Safety - 1 1 -
Finance - 3 - -
+++++++++++++++++++++++++++
Output:
E-Test 3 -
4 -
Health and Safety
- 1 1 -
Finance
- 3 - -
+++++++++++++++++++++++++++
Suppose that explains it.
As others have pointed out, as long as we don't know for sure how you
safely separate department name from the rest, we are still just guessing.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 8 Sep 2003 16:21:33 -0400
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Tk800.024 and Perl 5.8.1-RC4
Message-Id: <bjioci$bu5@netnews.proxy.lucent.com>
Does Tk800.024 work with perl 5.8.1-rc4?
I use solaris 2.8 with gcc 3.3.
The Tk800.024 was successfully built with perl 5.8.0, but
I got the error with perl 5.8.1-rc4.
Why does perl 5.8.1-rc4 not like '--center'?
Any suggestions?
=======
$ make
......
Manifying ../blib/man3/Tk::place.3
make[1]: Leaving directory `/d200/add-on/perl/Tk800.024/pod'
make[1]: Entering directory `/d200/add-on/perl/Tk800.024/demos'
cp widget ../blib/script/widget
/s5/twh/perl581/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)"
../blib/script/widget
Unrecognized switch: --center (-h will show valid options).
make[1]: *** [manifypods] Error 255
make[1]: Leaving directory `/d200/add-on/perl/Tk800.024/demos'
make: *** [subdirs] Error 2
------------------------------
Date: Mon, 8 Sep 2003 16:40:31 -0400
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: Tk800.024 and Perl 5.8.1-RC4
Message-Id: <bjipg3$c82@netnews.proxy.lucent.com>
just found out Tk800.025 was released and
it does not give me error when I make it.
------------------------------
Date: Mon, 8 Sep 2003 16:43:53 -0400
From: "Tulan W. Hu" <twhu@lucent.com>
Subject: Re: Tk800.024 and Perl 5.8.1-RC4
Message-Id: <bjipmd$c9e@netnews.proxy.lucent.com>
"Tulan W. Hu" <twhu@lucent.com> wrote in
> just found out Tk800.025 was released and
> it does not give me error when I make it.
but it gave me lots errors when I ran 'make test'
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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.
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 5465
***************************************