[16301] in Perl-Users-Digest
Perl-Users Digest, Issue: 3713 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 18 09:47:53 2000
Date: Tue, 18 Jul 2000 06:47:43 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <963928063-v9-i3713@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 18 Jul 2000 Volume: 9 Number: 3713
Today's topics:
Re: executing a WinNT process (Alan Honsinger)
Re: executing a WinNT process (Larry Rosler)
Extra Path Information in CGI (spurcell)
Re: Extra Path Information in CGI (Mark W. Schumann)
Fancy mail, need help (Glen Heide)
Re: Fancy mail, need help (wimmel)
Re: Fancy mail, need help (Peter Sundstrom)
Fast file reading (was Re: Trying to use an array as a (Gary E. Ansok)
File::Remote module can't re-open fh ()
Re: filehandle (Abigail)
Re: flock nonsense ? (John Armsby)
Re: flock nonsense ? (Tad McClellan)
Re: flock nonsense ? (John Armsby)
Re: flock nonsense ? (Bart Lateur)
Re: flock nonsense ? (John Armsby)
Re: flock nonsense ? (Jonathan Stowe)
Re: flock nonsense ? (Oleg Goryunov)
Re: Flock unsupported on which systems? (Villy Kruse)
Re: Flock unsupported on which systems? (William Herrera)
Form problem (Haazi2)
Re: Form problem (jason)
Re: Form problem (David Efflandt)
Re: Form problem (Haazi2)
Re: Form problem (jason)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Jul 2000 19:30:06 GMT
From: alan@igs.net.bbs@openbazaar.net (Alan Honsinger)
Subject: Re: executing a WinNT process
Message-Id: <3bRMkU$Xbp@openbazaar.net>
try this:
system("c:/my\ files/test.exe");
Alan
<sanjay33@my-deja.com> wrote in message news:8kva1s$t11$1@nnrp1.deja.com...
>
>
> I am trying to run a program on NT through my perl scripy using the
> 'system` command
>
> ie,
>
> system("c:/my files/test.exe");
>
> The problem is caused by the space in the direcroty name which WinNT
> allows. The shell complains about this call saying that it is not
> recognised as an executable program.
>
> Can anyone tell me how to solve it?
>
> thanks
> sanjay
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: 17 Jul 2000 21:40:02 GMT
From: lr@hpl.hp.com.bbs@openbazaar.net (Larry Rosler)
Subject: Re: executing a WinNT process
Message-Id: <3bRQH3$WC1@openbazaar.net>
[Reordered for logical flow of discourse.]
In article <8kvmp3$ohi$1@news.igs.net> on Mon, 17 Jul 2000 15:25:34 -
0400, Alan Honsinger <alan@igs.net> says...
> <sanjay33@my-deja.com> wrote in message news:8kva1s$t11$1@nnrp1.deja.com...
> >
> > I am trying to run a program on NT through my perl scripy using the
> > 'system` command
> >
> > ie,
> >
> > system("c:/my files/test.exe");
> >
> > The problem is caused by the space in the direcroty name which WinNT
> > allows. The shell complains about this call saying that it is not
> > recognised as an executable program.
> try this:
>
> system("c:/my\ files/test.exe");
That compiles into the identical string as the one reported to fail.
Try replacing the double-quotes by single-quotes, or doubling the
backslash.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 17 Jul 2000 17:40:02 GMT
From: skpurcell@hotmail.com.bbs@openbazaar.net (spurcell)
Subject: Extra Path Information in CGI
Message-Id: <3bRK52$V8I@openbazaar.net>
Hello,
I was reading Steins book on CGI.pm and have been trying to use "Extra Path"
info in one of my scripts.
He states in his book, page 95, that with a URL like this:
http://your.site/cgi-bin/random_pict2.pl/pictures
that this above converntional URL has extra path information. eg. the
/pictures. And that the actual script is the random_pic2.pl. And he mentions
that when the web server sees this URL that it scans from left to right
until it finds a valid CGI script. Which he says would be random_pict2.pl.
And that then he can pass the /pictures in as "extra Path info".
Anyway, I have jacked with this for quite some time, and I can't seem to get
it to work.
I set up a cgi-bin just like he has and made a simple .pl file called
random_pict2.pl.
And that works as long as I called it like
http://your.site/cgi-bin/random_pict2.pl
But as soon as I add the /pictures then I get burned.
Does anyone know how this "extra Path info" is suposed to work? It makes
sense how it works, but it don't work here.
Config: IIS
Active state Perl.
Thanks
Scott
------------------------------
Date: 18 Jul 2000 00:10:01 GMT
From: catfood@apk.net.bbs@openbazaar.net (Mark W. Schumann)
Subject: Re: Extra Path Information in CGI
Message-Id: <3bRUCS$UXy@openbazaar.net>
In article <397346cc$0$27161@wodc7nh1.news.uu.net>,
spurcell <skpurcell@hotmail.com> wrote:
>Anyway, I have jacked with this for quite some time, and I can't seem to get
>it to work.
>I set up a cgi-bin just like he has and made a simple .pl file called
>random_pict2.pl.
>And that works as long as I called it like
>http://your.site/cgi-bin/random_pict2.pl
>But as soon as I add the /pictures then I get burned.
What do you mean, "burned"? Does the script not go at all? Do you
get server errors? Does the script run but without the "extra path
info"?
>Does anyone know how this "extra Path info" is suposed to work? It makes
>sense how it works, but it don't work here.
>
>Config: IIS
>Active state Perl.
I suspect this might be a server "feature." Check your IIS docs to make
sure the "path info" thing is supported at all.
Oh, wait, look what turned up in a search engine under "path info iis":
http://www.geocities.com/SiliconValley/Bay/3464/0776.txt
This may address some or all of your problem.
------------------------------
Date: 17 Jul 2000 19:30:06 GMT
From: jheide@sprint.ca.bbs@openbazaar.net (Glen Heide)
Subject: Fancy mail, need help
Message-Id: <3bRMkb$VeI@openbazaar.net>
Does anyone know how to send an e-mail with HTML formatting using Perl?
I currently use the "sendmail" program on the Unix server to send a plain
text e-mail message.
--
Yours Truly,
Glen Heide
------------------------------
Date: 18 Jul 2000 00:10:01 GMT
From: wimmmel@hotmail.com.bbs@openbazaar.net (wimmel)
Subject: Re: Fancy mail, need help
Message-Id: <3bRUCR$UTz@openbazaar.net>
Glen Heide wrote:
>
> Does anyone know how to send an e-mail with HTML formatting using Perl?
> I currently use the "sendmail" program on the Unix server to send a plain
> text e-mail message.
>
> --
> Yours Truly,
> Glen Heide
To send HTML by e-mail (and have an email client know it's html), you'll
have to add a "Content-Type" header:
open(MAIL,"|sendmail -t") || die "Call to sendmail failed.";
print MAIL "Content-Type: text/html\n";
I used it on a script I use to get pages from the web into my mailbox,
in case I am at a place where I don't have web access (but of course do
have mail access to the internet).
wimmel
The script (in case you need an example) --> http://mailbrowser.dhs.org/
------------------------------
Date: 18 Jul 2000 04:00:03 GMT
From: peter.sundstrom@eds.com.bbs@openbazaar.net (Peter Sundstrom)
Subject: Re: Fancy mail, need help
Message-Id: <3bRaC4$VGK@openbazaar.net>
Glen Heide wrote in message
<3cJc5.10881$_J1.117916@newscontent-01.sprint.ca>...
>Does anyone know how to send an e-mail with HTML formatting using Perl?
>I currently use the "sendmail" program on the Unix server to send a plain
>text e-mail message.
Use the MIME::Lite module.
------------------------------
Date: 17 Jul 2000 17:10:02 GMT
From: ansok@alumni.caltech.edu.bbs@openbazaar.net (Gary E. Ansok)
Subject: Fast file reading (was Re: Trying to use an array as a hash value)
Message-Id: <3bRJFQ$VTb@openbazaar.net>
In article <slrn8muvn0.eq3.tadmc@magna.metronet.com>,
Tad McClellan <tadmc@metronet.com> wrote:
>On Fri, 14 Jul 2000 22:10:23 +0000, rhys <rhys.tucker@dtn.ntl.com> wrote:
>
>>slurp up a file into an array - @message = <MESSAGE>; and use this
>>somehow.
>>
>>I've been wondering that the solution may be to slurp up the file into a
>>scalar variable somehow?.
>
>
> my $message;
> {
> local $/; # undef is slurp mode
> $message = <MESSAGE>; # the whole file in a single scalar
> }
I did some benchmarking a while ago, and while I've misplaced the timing
data, I found that the fastest way to read an entire file (on both Solaris
and NT systems that I had access to) was
my $message;
binmode MESSAGE; # if your algorithm doesn't mind \r
sysread MESSAGE, $message, -s MESSAGE;
binmode made a huge difference on my Windows NT machine -- assuming your
processing doesn't mind the \r characters. In my case, I was using
\s+ for all whitespace matching and didn't care at all about lines,
so \r\n was equivalent to \n. (If you binmode your input, remember
you'll probably need to binmode your output as well.)
sysread was a minor win (compared to read) on Solaris, and negligible on
NT. Even read() was faster than using <> to slurp the file, though the
sysread/read/<> difference wasn't that large.
My input files were about 20K -- your mileage may vary, particularly
for much smaller or larger files. This was not done in a CGI environment.
--
Gary Ansok
------------------------------
Date: 17 Jul 2000 05:00:01 GMT
From: radome@mailexcite.com.bbs@openbazaar.net ()
Subject: File::Remote module can't re-open fh
Message-Id: <3bR0F1$V8M@openbazaar.net>
Hi
I have a script that opens a remote file for reading. I am using the
File::Remote library from CPAN. When I open the file, File::Remote adds
the $fh to a hash called $File::Remote::open_handles. If I close the
file it closes ok. If I re-open it, File::Remote looks first to ensure
it's not already open. File::Remote finds it in its hash, tries to
close it and fails with "bad file descriptor". I modified my copy of
Remote.pm to delete the $fh from the hash on a successful close but I
feel I'm missing something.
Should I not be calling the close method manually?
Should I be destroying the File::Remote object after the close?
Thanks for any input.
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 17 Jul 2000 19:30:06 GMT
From: abigail@delanet.com.bbs@openbazaar.net (Abigail)
Subject: Re: filehandle
Message-Id: <3bRMkV$Xfm@openbazaar.net>
Umesh (nair@ee.tamu.edu) wrote on MMDVIII September MCMXCIII in
<URL:news:Pine.GSO.4.21.0007131329420.13659-100000@eesun1.tamu.edu>:
__
__ Is it possible to get the filename by knowing only the filehandle ?
No.
The reason is that there isn't a 1-1 relation between filehandles and
filenames. It's a a many-to-many, for as little many as 0. A file can
have more than one name (hardlinks), or no name at all (that's why there
is a function unlink(), and delete() has nothing to do with files).
__ i.e the filehandle is passed to a subroutine (as a typeglob or object from
__ FileHandle), and i need to say print the name of file from within
__ subroutine?
Then you pass two arguments.
Abigail
--
print v74.117.115.116.32, v97.110.111.116.104.101.114.32,
v80.101.114.108.32, v72.97.99.107.101.114.10;
------------------------------
Date: 16 Jul 2000 14:10:02 GMT
From: jaws@mindspring.com.bbs@openbazaar.net (John Armsby)
Subject: Re: flock nonsense ?
Message-Id: <3bQP6Q$WT_@openbazaar.net>
As just a guy who wants the basics of file locking like everyone else,
I have followed these and other posts, compared code snippets, etc. To
use Fcntl or not to use Fcntl... to use semaphone files... not to use
semaphore files...not sure how semaphone files work.... Can I not
just avoid the problem by renaming the file to PID ($$), doing
something to it, and then renaming it back?
I have concurrently run the code below as test1.pl and test2.pl. I
changed test1.pl and test2.pl so that they would print slightly
different values. That way I could compare what each program was
doing to the common file.. It seems to work. Why should I agonize
with flock?
#!/usr/bin/perl/bin
$PID =$$;
print("\nPID is: $PID\n\n");
if ($PID !=NULL)
{
{
print("\ntrying to rename.....");
sleep 2;
redo until (rename("TestFile.txt",$PID));
}
print("\nopening OUTFILE...");
fflush;
open (OUTFILE,">>$PID") or die " can not open $PID";
for($i=0;$i<1000000;$i++)
{
print OUTFILE "\n$i"; # test1.pl print out
print OUTFILE "\nTest2$i"; # test2.pl print out
}
print("\nclosing the OUTFILE...");
close(OUTFILE);
print("\nOpening for reading....");
open(INFILE,"$PID") or die "can not open $PID";
while(<INFILE>)
{
$Line =$_;
next;
}
close(INFILE);
print("\n\nThe last line is $Line");
rename($PID,"TestFile.txt");
}
------------------------------
Date: 16 Jul 2000 16:10:02 GMT
From: tadmc@metronet.com.bbs@openbazaar.net (Tad McClellan)
Subject: Re: flock nonsense ?
Message-Id: <3bQSCR$X1q@openbazaar.net>
On Sun, 16 Jul 2000 14:15:32 GMT, John Armsby <jaws@mindspring.com> wrote:
>
>As just a guy who wants the basics of file locking like everyone else,
>I have followed these and other posts, compared code snippets, etc. To
>use Fcntl or not to use Fcntl... to use semaphone files... not to use
>semaphore files...not sure how semaphone files work.... Can I not
>just avoid the problem by renaming the file to PID ($$), doing
>something to it, and then renaming it back?
No.
"instance1" of your program renames a file named '123' (its PID).
"instance1" then loses its time slice.
"instance2" of your program renames a file named '456' (its PID).
"instance2" does some changes, moves the file back
and terminates.
"instance1" gets a turn, does some changes, moves the file back
and terminates.
"instance2"'s changes disappear!
>I have concurrently run the code below as test1.pl and test2.pl. I
>changed test1.pl and test2.pl so that they would print slightly
>different values. That way I could compare what each program was
>doing to the common file.. It seems to work. Why should I agonize
>with flock?
Because you cannot control the scheduling of jobs.
Multitasking is hard. CGI is multitasking. CGI is hard.
>#!/usr/bin/perl/bin
Surely you meant:
#!/usr/bin/perl -w
use strict;
Or similar. Naming your perl interpreter 'bin' is gonna be pretty confusing...
--
Tad McClellan SGML Consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: 16 Jul 2000 17:20:01 GMT
From: jaws@mindspring.com.bbs@openbazaar.net (John Armsby)
Subject: Re: flock nonsense ?
Message-Id: <3bQU42$VWC@openbazaar.net>
I don't see it. Instance 1 writes the file. Instance 2 waits until instance 1
is finished and then writes the file (append). When I run the programs they
append to the TestFile.txt.
John
On Sun, 16 Jul 2000, Tad McClellan wrote: >On Sun,
16 Jul 2000 14:15:32 GMT, John Armsby <jaws@mindspring.com> wrote: >>
>>As just a guy who wants the basics of file locking like everyone else,
>>I have followed these and other posts, compared code snippets, etc. To
>>use Fcntl or not to use Fcntl... to use semaphone files... not to use
>>semaphore files...not sure how semaphone files work.... Can I not
>>just avoid the problem by renaming the file to PID ($$), doing
>>something to it, and then renaming it back?
>
>
>No.
>
>"instance1" of your program renames a file named '123' (its PID).
>
>"instance1" then loses its time slice.
>
>"instance2" of your program renames a file named '456' (its PID).
>
>"instance2" does some changes, moves the file back
>and terminates.
>
>"instance1" gets a turn, does some changes, moves the file back
>and terminates.
>
>
>"instance2"'s changes disappear!
>
>
>
>>I have concurrently run the code below as test1.pl and test2.pl. I
>>changed test1.pl and test2.pl so that they would print slightly
>>different values. That way I could compare what each program was
>>doing to the common file.. It seems to work. Why should I agonize
>>with flock?
>
>
>Because you cannot control the scheduling of jobs.
>
>Multitasking is hard. CGI is multitasking. CGI is hard.
>
>
>
>>#!/usr/bin/perl/bin
>
>
>Surely you meant:
>
>
>#!/usr/bin/perl -w
>use strict;
>
>
>Or similar. Naming your perl interpreter 'bin' is gonna be pretty confusing...
>
>
>
>--
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
------------------------------
Date: 16 Jul 2000 17:40:01 GMT
From: bart.lateur@skynet.be.bbs@openbazaar.net (Bart Lateur)
Subject: Re: flock nonsense ?
Message-Id: <3bQUT1$XHe@openbazaar.net>
martho@my-deja.com wrote:
>> Yes: don't release the lock until you're done with the file. If you
>> need to read AND write from it, then open it for reading and writing.
>Okay, thats the solution. I didnÄt know that you could open a file for
>both. Thanks.
The mode is "+<", but careful: it only succeeds for files that exist.
"+>>" works for new files too, but I'm actually a bit surprised that it
can be used.
WHen you're done reading, do
seek FILE, 0, 0;
truncate FILE, 0;
and you're ready to write new contents.
>> See the open documentation.
>Where can I get it ? Everybody tells me to look at "perldoc ....", but
>in my perl-installtion, there is no file called so. I thank, I didn't
>get the doc-files.
perldoc is a perl script. In the Windows ports, it's a in the form of a
BAT file; in the same directory zs perl itself. At the command line (AKA
"DOS prompt", you can type:
perldoc -f open
optionally followed by "| more" or "> somefile.txt", which makes reading
easier.
I prefer doing this from within a text editor, one which allows you to
run external programs, capture the output, and show it in a new document
window.
--
Bart.
------------------------------
Date: 16 Jul 2000 17:30:03 GMT
From: jaws@mindspring.com.bbs@openbazaar.net (John Armsby)
Subject: Re: flock nonsense ?
Message-Id: <3bQUGS$WKP@openbazaar.net>
You are right on the #!/usr/bin..
I should have done the #!/usr/bin/perl..... I was just playing around this
morning and was not paying attention.
>Because you cannot control the
scheduling of jobs. >
>Multitasking is hard. CGI is multitasking. CGI is hard.
>
>
>
>>#!/usr/bin/perl/bin
>
>
>Surely you meant:
>
>
>#!/usr/bin/perl -w
>use strict;
>
>
>Or similar. Naming your perl interpreter 'bin' is gonna be pretty confusing...
>
>
>
>--
> Tad McClellan SGML Consulting
> tadmc@metronet.com Perl programming
> Fort Worth, Texas
------------------------------
Date: 17 Jul 2000 08:30:05 GMT
From: gellyfish@gellyfish.com.bbs@openbazaar.net (Jonathan Stowe)
Subject: Re: flock nonsense ?
Message-Id: <3bR5bX$UaN@openbazaar.net>
On Sun, 16 Jul 2000 14:15:32 GMT John Armsby wrote:
> Why should I agonize
> with flock?
>
I really dont get this, what precisely is wrong with the documentation that
people have such difficulty with it ?
--
yapc::Europe in assocation with the Institute Of Contemporary Arts
<http://www.yapc.org/Europe/> <http://www.ica.org.uk>
------------------------------
Date: 18 Jul 2000 07:20:11 GMT
From: ingenuous@mail.ru.bbs@openbazaar.net (Oleg Goryunov)
Subject: Re: flock nonsense ?
Message-Id: <3bRfMB$TXW@openbazaar.net>
> >Why should I agonize with flock?
> >
Jonathan Stowe:
> I really dont get this, what precisely is wrong with the
>documentation that people have such difficulty with it ?
>
It is rather interesting matter on locking a file over NFS.
The only right decision could be to publish a fragment of a Perl
program that indeed locks the file being OS independent. Instead
we see theoretical reasonings (or go to recommendations) without
any practical results (if they are, they are declared as wrong
ones). May be it's impossible at all - to lock a file over NFS
correctly? Is the locking a myth?
Indeed the perldoc is the first ring in the chain.
Oleg
------------------------------
Date: 17 Jul 2000 09:10:06 GMT
From: vek@pharmnl.ohout.pharmapartners.nl.bbs@openbazaar.net (Villy Kruse)
Subject: Re: Flock unsupported on which systems?
Message-Id: <3bR6dU$Vfg@openbazaar.net>
On Sat, 15 Jul 2000 10:23:47 +0200, Bart Lateur <bart.lateur@skynet.be> wrote:
>Clinton A. Pierce wrote:
>
>>> "perldoc perlport" doesn't say flock() is not supported on Windows systems... So would it be safe to
>>> assume that it IS supported?
>
>No it's not.
>
>>Systems which don't have flock() generally don't need it. (Win95/Win98)
>>The existance of flock can be tested for with eval.
>
>But that's annoying!
>
>I prefer the way the DJGPP DOS Perl handles it: flock() is simply a
>noop. If only the Win32 Perls behaved the same way. Life would be much
>nicer.
>
Except if you need to lock the file and the system just pretends that
the lock was successful when in fact it wasn't, you have a potential
problem. If you access files on a SMB share then file locking might
be very relevant, even in win9x systems.
Villy
------------------------------
Date: 18 Jul 2000 04:30:03 GMT
From: posting.account@lynxview.com.bbs@openbazaar.net (William Herrera)
Subject: Re: Flock unsupported on which systems?
Message-Id: <3bRb1S$Vrf@openbazaar.net>
On 17 Jul 2000 15:18:59 GMT, The WebDragon <nospam@nospam.com> wrote:
>
>flock(); is unsupported on the current version of MacPerl (which problem
>will definitely go away with MacOS X (since it will run perl natively),
>and may possibly go away with the next release of MacPerl (if and when
>it gets released .. current version (520r4) is essentially 5.004)
Well, there is always the File::FlockDir module on CPAN, which enables flock
across networks and on Windows9x and MaxPerl. Though it really has not been
used much on Macs AFAIK.
---
The above from: address is spamblocked. Use wherrera (at) lynxview (dot) com for the reply address.
------------------------------
Date: 16 Jul 2000 14:20:02 GMT
From: haazi2@aol.com.bbs@openbazaar.net (Haazi2)
Subject: Form problem
Message-Id: <3bQPJ3$UqN@openbazaar.net>
Well, I thought I had solved everything but I have one more bug in
my perl script. I use an HTML form and then process it with a perl script.
If there are errors in the required fields the perl script should redraw the
form
with the data that was entered in the HTML form. If the the required fields are
correct then the perl script generates a thank you message to the user.
Here's the problem:
If the user fills out the required fields with the correct values and clicks on
the next button, the user will get error messages about the required fields
which is wrong. However if the user submits the info a second time, filling out
the required fields correctly, you will get a thank you message. It seems the
field values submitted from the HTML form are lost some how. How do I make sure
I keep the form values submitted from the HTML form? Thanks for any help in
advance.
------------------------------
Date: 16 Jul 2000 22:50:01 GMT
From: elephant@squirrelgroup.com.bbs@openbazaar.net (jason)
Subject: Re: Form problem
Message-Id: <3bQcWQ$Uy1@openbazaar.net>
Haazi2 wrote ..
>Well, I thought I had solved everything but I have one more bug in
>my perl script. I use an HTML form and then process it with a perl script.
>If there are errors in the required fields the perl script should redraw the
>form
>with the data that was entered in the HTML form. If the the required fields are
>correct then the perl script generates a thank you message to the user.
>
>Here's the problem:
>
>If the user fills out the required fields with the correct values and clicks on
>the next button, the user will get error messages about the required fields
>which is wrong. However if the user submits the info a second time, filling out
>the required fields correctly, you will get a thank you message. It seems the
>field values submitted from the HTML form are lost some how. How do I make sure
>I keep the form values submitted from the HTML form? Thanks for any help in
>advance.
"in advance" is right !!
in the absence of any code or real explanation of what you're doing -
here's a diagnostic clue -> in your browser - view the source of both
the original HTML form and the form that your code generates - there
will almost certainly be some obvious differences - either in the INPUT
field names or in the FORM tag details
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: 17 Jul 2000 02:10:02 GMT
From: efflandt@xnet.com.bbs@openbazaar.net (David Efflandt)
Subject: Re: Form problem
Message-Id: <3bQhgQ$XXe@openbazaar.net>
On 16 Jul 2000 14:21:55 GMT, Haazi2 <haazi2@aol.com> wrote:
>Well, I thought I had solved everything but I have one more bug in
>my perl script. I use an HTML form and then process it with a perl script.
>If there are errors in the required fields the perl script should redraw the
>form
>with the data that was entered in the HTML form. If the the required fields are
>correct then the perl script generates a thank you message to the user.
>
>Here's the problem:
>
>If the user fills out the required fields with the correct values and clicks on
>the next button, the user will get error messages about the required fields
>which is wrong. However if the user submits the info a second time, filling out
>the required fields correctly, you will get a thank you message. It seems the
>field values submitted from the HTML form are lost some how. How do I make sure
>I keep the form values submitted from the HTML form? Thanks for any help in
>advance.
Generate the original form and any subsequent forms with CGI.pm. Then it
is easy to make sure that they have the same name (case is significant).
That also makes it easy to replicate the filled in form for further
corrections. Submitted values override default values unless you
specifically reasign the value to that param or include -override=>1
when printing form fields.
--
David Efflandt efflandt@xnet.com http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
http://hammer.prohosting.com/~cgi-wiz/ http://cgi-help.virtualave.net/
------------------------------
Date: 17 Jul 2000 05:00:02 GMT
From: haazi2@aol.com.bbs@openbazaar.net (Haazi2)
Subject: Re: Form problem
Message-Id: <3bR0F4$VKL@openbazaar.net>
I do apologize for not posting the code:
Here's the HTML listing:
<html>
<head><title>sample</title><head>
<body>
<br><br>
<h1> TEST SCRIPT </h1>
<a href="/test/cgi-bin/process.pl">Test cgi script</a>
</body>
</html>
Here's the perl script:
#! /usr/local/bin/perl
# program test processing form data
use strict;
use CGI qw(:standard);
if (param()) {
my $error = 'n';
my $favorite = param("favorites");
my $name = param("name");
if ( $favorite eq "" || $name eq "" ) {
$error = 'y';
}
if ( $name =~ /\./g ) {
$error = 'y';
}
if ( $error eq 'y' ) {
print <<HTMLBEG;
Content-type: text/html
<html>
<head><title>test form</title></head>
<body>
<form method=post action="process.pl" name="testform">
<b>Please correct your errors!</b>
<p>error = $error<p>
<p>favorite = $favorite<p>
<p>name = $name<p>
<br><br>
HTMLBEG
;
if ( $favorite eq "yellow" ) {
print(" <input type=\"radio\" name=\"favorites\"
value=\"yellow\" checked> yellow <br>\n");
} else {
print(" <input type=\"radio\" name=\"favorites\"
value=\"yellow\"> yellow <br>\n");
}
if ( $favorite eq "red" ) {
print(" <input type=\"radio\" name=\"favorites\" value=\"red\"
checked> red <br>\n");
} else {
print(" <input type=\"radio\" name=\"favorites\" value=\"red\">
red <br>\n");
}
if ( $favorite eq "blue" ) {
print(" <input type=\"radio\" name=\"favorites\" value=\"blue\"
checked> blue <br>\n");
} else {
print(" <input type=\"radio\" name=\"favorites\" value=\"blue\">
blue <br>\n");
}
if ( $favorite eq "green" ) {
print(" <input type=\"radio\" name=\"favorites\" value=\"green\"
checked> green <br>\n");
} else {
print(" <input type=\"radio\" name=\"favorites\"
value=\"green\"> green <br>\n");
}
print <<HTMLEND;
<br>
<b>NAME*</b><br>
<input type="text" name="$name">
<br>
<br>
<input type="submit" value="NEXT">
</form>
</body>
</html>
HTMLEND
;
} else {
print <<MSG;
Content-type: text/html
<html>
<head><title>test form</title></head>
<body>
<br>
<br>
<h1>Thank you.</h1>
</body>
</html>
MSG
;
}
} else {
print <<BEG_HTML;
Content-type: text/html
<html>
<head><title>test form</title></head>
<body>
<form method="post" action="process.pl" name="testform">
<input type="radio" name="favorites" value="yellow"> yellow <br>
<input type="radio" name="favorites" value="red"> red <br>
<input type="radio" name="favorites" value="blue"> blue <br>
<input type="radio" name="favorites" value="green"> green <br>
<br>
<b>NAME*</b><br>
<input type="text" name="fname">
<br>
<br>
<input type="submit" value="NEXT">
</form>
</body>
</html>
BEG_HTML
;
}
When the user submits the form with the correct value the radio button is saved
but data for the name field is lost. Any ideas?
------------------------------
Date: 17 Jul 2000 06:20:01 GMT
From: elephant@squirrelgroup.com.bbs@openbazaar.net (jason)
Subject: Re: Form problem
Message-Id: <3bR2J1$UqL@openbazaar.net>
[ posted to comp.lang.perl.misc and CCed to haazi2@aol.com ]
Haazi2 wrote ..
>#! /usr/local/bin/perl
>
># program test processing form data
>use strict;
>use CGI qw(:standard);
>
>if (param()) {
> my $error = 'n';
> my $favorite = param("favorites");
> my $name = param("name");
>
> if ( $favorite eq "" || $name eq "" ) {
> $error = 'y';
> }
>
> if ( $name =~ /\./g ) {
> $error = 'y';
> }
>
> if ( $error eq 'y' ) {
> print <<HTMLBEG;
> Content-type: text/html
>
> <html>
> <head><title>test form</title></head>
> <body>
> <form method=post action="process.pl" name="testform">
> <b>Please correct your errors!</b>
> <p>error = $error<p>
> <p>favorite = $favorite<p>
> <p>name = $name<p>
> <br><br>
>HTMLBEG
>;
> if ( $favorite eq "yellow" ) {
> print(" <input type=\"radio\" name=\"favorites\"
>value=\"yellow\" checked> yellow <br>\n");
> } else {
> print(" <input type=\"radio\" name=\"favorites\"
>value=\"yellow\"> yellow <br>\n");
> }
>
> if ( $favorite eq "red" ) {
> print(" <input type=\"radio\" name=\"favorites\" value=\"red\"
>checked> red <br>\n");
> } else {
> print(" <input type=\"radio\" name=\"favorites\" value=\"red\">
>red <br>\n");
> }
>
> if ( $favorite eq "blue" ) {
> print(" <input type=\"radio\" name=\"favorites\" value=\"blue\"
>checked> blue <br>\n");
> } else {
> print(" <input type=\"radio\" name=\"favorites\" value=\"blue\">
>blue <br>\n");
> }
>
> if ( $favorite eq "green" ) {
> print(" <input type=\"radio\" name=\"favorites\" value=\"green\"
>checked> green <br>\n");
> } else {
> print(" <input type=\"radio\" name=\"favorites\"
>value=\"green\"> green <br>\n");
> }
>
> print <<HTMLEND;
> <br>
> <b>NAME*</b><br>
> <input type="text" name="$name">
> <br>
> <br>
> <input type="submit" value="NEXT">
> </form>
> </body>
> </html>
>HTMLEND
>;
> } else {
> print <<MSG;
> Content-type: text/html
> <html>
> <head><title>test form</title></head>
> <body>
> <br>
> <br>
> <h1>Thank you.</h1>
> </body>
> </html>
>MSG
>;
> }
>
>} else {
>
> print <<BEG_HTML;
> Content-type: text/html
>
> <html>
> <head><title>test form</title></head>
> <body>
> <form method="post" action="process.pl" name="testform">
> <input type="radio" name="favorites" value="yellow"> yellow <br>
> <input type="radio" name="favorites" value="red"> red <br>
> <input type="radio" name="favorites" value="blue"> blue <br>
> <input type="radio" name="favorites" value="green"> green <br>
> <br>
> <b>NAME*</b><br>
> <input type="text" name="fname">
> <br>
> <br>
> <input type="submit" value="NEXT">
>
> </form>
> </body>
> </html>
>
>BEG_HTML
>;
>
>}
so .. let me remind the viewers of the problem (which fortunately I
remember) .. you click on the link and the script produces a form to be
filled in .. when you fill it in the first time - the text field doesn't
seem to get into the script correctly .. but when you submit the form
the second time (and subsequent times) the values find their way into
your script
your problem arises because your script is expecting param("name") to
give the value of the text field .. but the 'else' clause of your script
outputs the following HTML
<input type="text" name="fname">
so .. the first time the form is produced for the browser the text field
is called "fname" .. but your script is wanting "name" .. hence it gets
no value
a warning .. the second time - the name of the text field is the VALUE
of the text field from the submission .. so on the second and subsequent
submissions if you put anything other than "name" in that text field
then the script would also not work
at the risk of giving you an answer that prevents you from learning ..
but in the hope of showing you some things for your program .. here's
how I would code your logic using the same output method that you're
using - because it would actually be better to use the CGI module's
output methods .. but one thing at a time
note the flow of the code .. you have three paths through your code ..
one where the code is being executed for the first time .. one where
there's an error .. and the default code path where you've got the
values you need and just send a thank you .. I think you'll agree that
it's clearer having these paths as separate subroutines - rather than in
large nested conditionals
there are also some corrections .. the HTTP headers should not have
leading spaces .. and your "thank you" output didn't have a blank line
between the headers and the HTML
and one functionality alteration - the $error code is not output ..
because if we're in that path of code then it will always be the same
thing
#!/usr/local/bin/perl
use strict;
use CGI qw(:standard);
my $favorite = param('favorite');
my $name = param('name');
# is this the first time this script has been called ?
first() unless defined $favorite and defined $name;
# check the values of those vars and make sure there's no '.' in $name
error() if $favorite eq '' or $name eq '' or index( $name, '.') > -1;
# if it was all ok then say thank you
print <<__END;
Content-type: text/html
<html>
<head><title>test form</title></head>
<body>
<br>
<br>
<h1>Thank you.</h1>
</body>
</html>
__END
sub error
{
print <<__END;
Content-type: text/html
<html>
<head><title>test form</title></head>
<body>
<form method=post action="process.pl" name="testform">
<b>Please correct your errors!</b>
<p>favorite = $favorite<p>
<p>name = $name<p>
<br><br>
__END
# loop through the four radio values testing and checking as we go
for( qw/yellow red blue green/ )
{
print qq[ <input type="radio" name="favorite" value="$_"]
, ( $_ eq $favorite ? ' checked' : '' )
, qq[> $_ <br>\n]
;
}
print <<__END;
<br>
<b>NAME*</b><br>
<input type="text" name="name" value="$name">
<br>
<br>
<input type="submit" value="NEXT">
</form>
</body>
</html>
__END
exit;
}
sub first
{
print <<__END;
Content-type: text/html
<html>
<head><title>test form</title></head>
<body>
<form method="post" action="process.pl" name="testform">
<input type="radio" name="favorite" value="yellow"> yellow <br>
<input type="radio" name="favorite" value="red"> red <br>
<input type="radio" name="favorite" value="blue"> blue <br>
<input type="radio" name="favorite" value="green"> green <br>
<br>
<b>NAME*</b><br>
<input type="text" name="name">
<br>
<br>
<input type="submit" value="NEXT">
</form>
</body>
</html>
__END
exit;
}
__END__
--
jason -- elephant@squirrelgroup.com --
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3713
**************************************