[18986] in Perl-Users-Digest
Perl-Users Digest, Issue: 1181 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 23 21:05:31 2001
Date: Sat, 23 Jun 2001 18:05:07 -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: <993344707-v10-i1181@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sat, 23 Jun 2001 Volume: 10 Number: 1181
Today's topics:
.htaccess help required <ub98aa@brocku.ca>
Re: command line news posting tools <sun_tong@users.sourceforge.net>
curses and curses::forms <steuer@mediasponsor.com>
Re: Getting http file and parsing it. Help please. <krahnj@acm.org>
Re: How to detect 'Out of Space' (Clinton A. Pierce)
Re: http://stein.cshl.org/WWW/software/CGI/#dos <davsoming@lineone.net>
Merging two scripts (cd)
Re: my $ref; vs. my $ref = {}; <temp133@hotmail.com>
Re: Password encryption <dddarrel@mediaone.net>
Re: Perl *is* strongly typed (was Re: Perl description) <goldbb2@earthlink.net>
Re: Perl *is* strongly typed (was Re: Perl description) (Sweth Chandramouli)
Re: perl book hzi@uol.com.br
Re: Problem reading large files (dumb question?) <krahnj@acm.org>
Re: Search and replace ONLY outside "quotes" <godzilla@stomp.stomp.tokyo>
Re: Search and replace ONLY outside "quotes" (Eric Bohlman)
Re: Search and replace ONLY outside "quotes" (Tad McClellan)
Six degrees of separation <boxrec@uklinux.net>
Re: Six degrees of separation <james@zephyr.org.uk>
Trouble checking params from a form <ted9669@antijunk.yahoo.com>
variables from cookie ? <richard@peterparkerDOTdemon.co.uk>
Re: Why does this split not work? <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sat, 23 Jun 2001 17:09:51 -0400
From: Umair Tariq Bajwa <ub98aa@brocku.ca>
Subject: .htaccess help required
Message-Id: <3B35059F.D3069E0F@brocku.ca>
I am designing and developing database. To access database the user
enters his login and password that are in usersfile created through
htpasswd command. Is there a way to connect to mysql database and check
for a valid user and password instead of going through that file?
Actually so many people are going to use that database and I think using
password file is not a good idea.
Does anyone know how to do that? Any help will be greatly appreciated.
Thanks in advance.
Umair
--
Favorite Quotes:
===============
"The box said 'Windows 95 or better', so I installed Linux"
-- Unknown
"A computer without Windows is like a chocolate cake without mustard."
-- Unknown
------------------------------
Date: 23 Jun 2001 14:13:47 -0300
From: * Tong * <sun_tong@users.sourceforge.net>
Subject: Re: command line news posting tools
Message-Id: <sa8k8233yr8.fsf@suntong.personal.users.sourceforge.net>
* Tong * <sun_tong@users.sourceforge.net> writes:
> Please suggest a news posting tool that can be used from command
> line, which has the function that like 'sendmail -t' (scanned
> message for headers) TIA
Thanks Philip Newton for sharing his code with me. Here is my
shell-script solution: (Oh, programming in Perl is just fun)
perl -e '
use strict;
use Net::NNTP;
my $n = Net::NNTP->new("news");
my @article = <>;
$n->post(\@article) or die "Post error: $!";
$n->quit;' ${1+"$@"}
Tested and worked perfectly.
Note from Phil, This just blasts the pipe content (which must be a
complete news article, with Newsgroups:, From:, Subject:,
etc. headers) to the news server mentioned.
--
Tong (remove underscore(s) to reply)
*niX Power Tools Project: http://xpt.sourceforge.net/
- All free contribution & collection
------------------------------
Date: Sat, 23 Jun 2001 21:45:27 +0200
From: "H. Steuer" <steuer@mediasponsor.com>
Subject: curses and curses::forms
Message-Id: <3B34F1D7.2402F20@mediasponsor.com>
Hello everybody,
does anyone know where to get some documentation about how to
use curses and curses::forms ?
The POD docs and curses man pages dont describe enough for a curses
beginner.
And the test.pl isnt very helpful, too, cause is just explains calendar
and simple input fields. (but no list boxes)
Thanks in advance
Heri
------------------------------
Date: Sat, 23 Jun 2001 21:42:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Getting http file and parsing it. Help please.
Message-Id: <3B350D45.878DD6A6@acm.org>
Sol Hell wrote:
>
> You need to escape the "-" dash characters inside the regex.
No, you don't.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 23 Jun 2001 18:06:13 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: How to detect 'Out of Space'
Message-Id: <pU4Z6.116523$DG1.19251308@news1.rdc1.mi.home.com>
[Posted and mailed]
In article <9h20d7$avcqo$1@id-93885.news.dfncis.de>,
"Aman Patel" <patelnavin@icenet.net> writes:
> Heres a small script (made up)
>
> open ( FILE, ">test.file" )
> print FILE "this is a test...";
> close (FILE);
>
> how do I know if the file system created the file?? does close return any
> error?
It did, you just ignored it. The return value from open() will tell you
if the file was created. The canonical way of checking this is:
open(FILE, ">test.file") || die "Cannot create: $!";
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Sat, 23 Jun 2001 20:40:47 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: http://stein.cshl.org/WWW/software/CGI/#dos
Message-Id: <tj9rpl516l841b@corp.supernews.co.uk>
<snipped>
> > Size is the size of the field when displayed in the browser. Maxlength
> > is the maximum number of characters that a user can enter.
>
> Yes, but don't forget, just because you tell the browser to limit the
> number of characters to send, doesn't mean that it necessarily will.
>
> You should both include a size parameter to the input tag, AND have your
> script test that the amount sent is less than your limit.
>
I already have: <INPUT TYPE="text" NAME="email" SIZE="25" MAXLENGTH="30"> on
html form.
I was wanting to know if $CGI::POST_MAX could be altered to also limit users
input using my program:
#!/usr/bin/perl
#use CGI.pm ?
#$CGI::POST_MAX here?
require "subparseform.lib";
&Parse_Form;
$email = $formdata{'email'};
open (EMAILS, ">>address.txt");
flock(EMAILS, 2);
print EMAILS "$email\n";
flock(EMAILS, 8);
close (EMAILS);
print "Content-type: text/html\n\n";
print "Your email address ($email) has been successfully entered for our
newsletter.";
print "Thank you. You will receive a confirmation email shortly.";
$from = "newsletter\@mydomain.com";
open (MAIL, "|/usr/sbin/sendmail -t") || &ErrorMessage;
print MAIL "To: $email \nFrom: $from\n";
print MAIL "Confirmation Email\n\n";
print MAIL "Thank you for signing up. Your email address ($email) has
been added successfully!\n\n";
print MAIL "Have a nice day.\n";
close (MAIL);
sub ErrorMessage {
print "<P>The server has a problem. Aborting script. \n";
exit;
}
Would the alternative be an if statement such as (not tested):
if ($run =~ /Submit/i){
&check_data;
}
sub check_data{
if ($email =~ tr/a-zA-Z0-9@.'-_//c) {
die $errormessage = "Special characters are forbidden. You used one in the
email field. Please use your browsers back button to correct the mistake.
ERROR";
&errorpage;}
{ die 'PLEASE NOTE: The EMAIL field is restricted to Max = 30 characters!
Software error checking' if length $email > 30;
}
}
Thanks
--
David Soming
'Just a head-banger- doing what I do best'
______________
------------------------------
Date: Sat, 23 Jun 2001 23:21:33 GMT
From: cd001@telus.net (cd)
Subject: Merging two scripts
Message-Id: <3b35cc5e.20906676@news.telus.net>
I have a script which emails out two messages using information from a
form. The emails go out in HTML format to two different email
addresses and it works really well...
I have another script which works well creating and maintaining a flat
database. I would like to have the information entered in the form go
to the email script and to be entered into the database as well....
Is there any way to do this? Do I merge the scripts? Call one from the
other? Forget this idea all together?
Any help would be appreciated...
Thanks....
------------------------------
Date: Sat, 23 Jun 2001 10:08:46 -0700
From: "Arvin Portlock" <temp133@hotmail.com>
Subject: Re: my $ref; vs. my $ref = {};
Message-Id: <9h2igf$uhk$1@agate.berkeley.edu>
Thanks. It's all so obvious now that you've explained it and
clears up some fuzziness I've had on the subject. The example
I included was illustrative rather than practical. But sometimes
I'll do something very similar so that later I can do things like:
if ($hashref)
because if (keys %{$hashref}) is inefficient and 'if exists' only works
when I know a specific key will always be present if the hash is
defined. I see now that if I want to perform such a test I should
avoid declaring the reference as $hashref = {}.
My problems in the past with declaring plain 'my $hashref;' were along
the lines that sometimes such a test would still return true even if no
keys seemed to have been created. I wondered whether perl would
sometimes turn $hashref into an actual reference to a hash based on
code in other areas of the subroutine, i.e., just the fact that the
subroutine
contained $hashref-> *anywhere* would be enough for it to do this.
Small tests I have performed seem to prove it does not, so those
anamolous results were most probebly due to other errors in my code.
Thanks again for clearing this up.
Philip Newton <pne-news-20010620@newton.digitalspace.net> wrote in message
news:pvj1jtc86emusud4er8ov4c7j2proe21gc@4ax.com...
> On Wed, 20 Jun 2001 09:23:22 -0700, "Arvin Portlock"
> <temp133@hotmail.com> wrote:
>
> > Is there a difference between declaring a hash reference as my $ref =
{};
> > and as just plain my $ref; ?
>
> The first creates an anonymous hash and puts a reference to it into
> $ref, the second leaves $ref with the undefined value.
>
> Note that if you use an undefined value as if it were a hash reference,
> Perl automagically conjures up an anonymous hash and sticks a reference
> to it into the variable so that you can reference it. Thus, this:
>
> $ref = undef;
> $ref->{'foo'} = 42;
>
> works, and $ref contains a hash reference afterwards.
>
> > The former has the advantage of being somewhat self-documenting,
>
> There is that.
>
> > sub make_hash {
> > my ($key, $value) = @_;
> > my $hashref;
> > $hashref->{$key}++ if $value;
> > return $hashref;
> > }
>
> This doesn't make a whole lot of sense to me. You return either undef or
> a reference to a hash with just one key.
>
> Cheers,
> Philip
> --
> Philip Newton <nospam.newton@gmx.li>
> Yes, that really is my address; no need to remove anything to reply.
> If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 24 Jun 2001 00:16:18 GMT
From: "Darrel Donaldson" <dddarrel@mediaone.net>
Subject: Re: Password encryption
Message-Id: <mjaZ6.1032$m6.953305@typhoon.ne.mediaone.net>
I don't know much about unix_md5_crypt usage but if this is indeed you code
you might try adding an = before @_ in your authCryptPassword subroutine.
sub authCryptPassword
{
my ($plaintextpassword)@_;
^
|
should have = here.
This might explain why the password doesn't get greated correctly.
/Darrel
------------------------------
Date: Sat, 23 Jun 2001 02:43:44 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <3B343AA0.1B162B77@earthlink.net>
Mark Jason Dominus wrote:
>
> In article <m1y9qk9xzu.fsf_-_@halfdome.holdit.com>,
> Randal L. Schwartz <merlyn@stonehenge.com> wrote:
> >No, Perl has strong compile-time typing for primitive data types
> >(scalars, arrays, hashes, filehandles),
>
> I cannot imagine what you might mean by this, since each of these is
> converted to the others automatically upon request, and hardly any
> checking is done. If this qualifies as 'strong typing' then I must
> conclude that 'strong typing' no longer has any meaning at all.
>
> >The compiler will abort if you try to put an array into a hash
> >variable: in fact, it can't even be specified because of the prefix
> >characters and the context they provide.
>
> Again, I think this makes a mockery of the concept of strong typing.
> It seems to me that the only way to accept this and still have a
> logical, consistent meaning for 'strongly typed' is to accept a
> trivial definition, so that *every* language is strongly typed. If
> you do this, the concept of 'strongly typed' uses any usefulness it
> might have had.
Maybe he was thinking about how perl reacts to stuff like this:
my ($x,$y) = ( {}, [] );
print @$x, $x->[0]; # any of these four dereference attempts
print %$y, $y->{0}; # will cause perl to abort.
[snip]
> >C++, by contrast, has strong compile-time typing, but weak run-time
> >typing, because you can cast a pointer to another type and call a
> >totally broken method on it. Crash!
>
> I suppose this is your example, but I don't find it very illuminating,
> because you can do an analogous thing in Perl:
>
> my $randal = PerlExpert->new(NAME => "Randal Schwartz");
> $randal->{number_of_wheels} = 18;
> $randal->{temperature_of_fusion} = "1600 Kelvins";
> bless $randal => 'Adorable_Doggie';
> $randal->wag_tail(); # Totally broken method! Crash!
>
> I don't see how you conclude from this anything about the relative
> run-time typing strength of C++ and Perl.
Well, maybe not from *that* example. But how about from this one:
C code:
int main() { char x; printf("%d\n", *(int*)&x ); }
Perl code:
main: { my $x = [0]; printf("%d\n", $x->{0} ); }
Neither of these will produce any error at compile time, but at runtime,
the C code will try to read from memory it shouldn't be reading from
(and possibly crash), but the Perl code will detect the problem, print
an appropriate error message, and exit.
Another example:
perl -e "[]->{0}"
If Perl were loosly typed, perl would actually call the hash fetch
subroutines with the reference to an array. Since it's not that loosly
typed, it detects that the lhs is not a hash ref, and prints out an
error message and exits.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Sat, 23 Jun 2001 07:25:28 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Perl *is* strongly typed (was Re: Perl description)
Message-Id: <IvXY6.2443$Ga.502962@news1.rdc1.md.home.com>
In article <3b33b536.37c$36b@news.op.net>,
Mark Jason Dominus <mjd@plover.com> wrote:
>In Perl,
>
> @a = %h
>and
> %h = @a
>
>are perfectly legal, and the compiler will not raise an error or even
>a warning for them; it will instead apply an automatic conversion.
>This behavior would appear to be the exact opposite of 'strongly
>typed'.
There's more to casting than assignment restrictions, though.
You can't do things like
my @a;
$a{'foo'};
, and have the second statement act on @a; because the {...} index
lookup syntax isn't defined for an array, the second statement can only
act on %a. If you're using strict 'vars', then, the above becomes
illegal, because Perl won't convert @a into a hash for this purpose, and
isn't allowed to use the undeclared %a. Using warnings can actually add
some minimal typing at the integer/string level as well; I think you
actually did a discussion of this that I read at some point. I'm not
denying your assertion that if Perl is strongly typed, then so is nearly
everything else; it's just that Perl isn't as weakly typed as it might
seem at first glance. (ksh93, for example, also has both associative and
indexed arrays, and in that language there is no real type distinction
between them, so you can do things like
$ set -A foo
$ foo[1]=1
$ foo[bar]=2
$ print ${foo[@]}
2 1
. I'd definitely say that that is weaker typing than Perl
provides.).
-- Sweth.
--
Sweth Chandramouli ; <sweth+perl@gwu.edu>
------------------------------
Date: Sun, 24 Jun 2001 09:03:34 +0000
From: hzi@uol.com.br
Subject: Re: perl book
Message-Id: <9h37cb$c1dma$1@ID-78052.news.dfncis.de>
In article <9dp10g$k3m$1@orphan.emich.edu>, "Frank A" <frank673@hotmail.com> wrote:
> Hi,
> Can anyone refer to a good perl book Thanks.
>
> Frank
>
>
Hi-
Beginning Perl, Wrox Press, by Simon Cozens.
Regards,
hzi
------------------------------
Date: Sat, 23 Jun 2001 22:52:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Problem reading large files (dumb question?)
Message-Id: <3B351D91.42695172@acm.org>
"Richard J. Rauenzahn" wrote:
>
> Or, simply...
>
> #!/opt/perl5/bin/perl -w
> use strict;
>
> open OUT, ">d.dat" || die;
^^^^^^
This doesn't do what you seem to think it does. You need to use "open()"
or "or". to get die to do anything. You should also include the $!
variable for a meaningful message.
open( OUT, ">d.dat" ) || die;
# OR
open OUT, ">d.dat" or die;
$ perl -MO=Deparse -le 'open IN, "< file.txt" || die'
-e syntax OK
open IN, '< file.txt';
$ perl -MO=Deparse -le 'open IN, "< file.txt" or die'
-e syntax OK
die unless open IN, '< file.txt';
$ perl -MO=Deparse -le 'open( IN, "< file.txt" ) || die'
-e syntax OK
die unless open IN, '< file.txt';
$ perl -le 'open IN, "< file.txt" || die'
$ perl -le 'open IN, "< file.txt" or die'
Died at -e line 1.
$ perl -le 'open IN, "< file.txt" or die "$!"'
No such file or directory at -e line 1.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 23 Jun 2001 08:20:06 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Search and replace ONLY outside "quotes"
Message-Id: <3B34B3A6.30BF15E4@stomp.stomp.tokyo>
Weston Cann wrote:
(snipped)
> I'm wondering what the laziest way to accomplish this is.
A rather lazy way to accomplish this is to not post any
sample code and ask others to write code for you. However,
many consider this approach to be very rude.
> Is there another way to do it?
Yes. Post sample code and ask for improvement ideas. This
would be a polite approach.
Godzilla!
------------------------------
Date: 23 Jun 2001 15:42:54 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Search and replace ONLY outside "quotes"
Message-Id: <9h2ddu$c57$1@bob.news.rcn.net>
Weston Cann <iowa8_song8.REMOVE_EIGHTS_AND_THIS@hotmail.com> wrote:
> I've been running global searches and replaces on a number of html files
> using a perl script. Up until now, I've just slurped the whole file into
> a string, and done s///mg on the string.
> I've been informed, however, that I shouldn't be searching and replacing
> inside tags.
> I'm wondering what the laziest way to accomplish this is. The one I can
Use HTML::Parser if you want a "push" (callback) interface, or
HTML::TokeParser if you want a "pull" (read next item) interface. Both of
them will accurately distinguish between text that's part of content and
text that's part of markup, and learning either will probably take less
time than debugging and testing "hand rolled" code.
------------------------------
Date: Sat, 23 Jun 2001 11:03:49 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Search and replace ONLY outside "quotes"
Message-Id: <slrn9j9bul.58r.tadmc@tadmc26.august.net>
Weston Cann <iowa8_song8.REMOVE_EIGHTS_AND_THIS@hotmail.com> wrote:
>I've been running global searches and replaces on a number of html files
>using a perl script. Up until now, I've just slurped the whole file into
>a string, and done s///mg on the string.
Why the "m"? Do you have anchors ( ^ or $ ) in your pattern?
"lines" don't mean much in HTML, so I doubt you should have anchors...
Do you mean "s" instead? Do you have dot ( . ) in your pattern?
>I've been informed, however, that I shouldn't be searching and replacing
>inside tags.
You should use one of the HTML parsing modules for parsing HTML.
>I'm wondering what the laziest way to accomplish this is.
It depends on how robust you require it to be. Do you control the
HTML so that you can be guaranteed that no "legal but strange"
stuff will occur in the data?
If not, then you should not attempt to get the job done with regexes.
>The one I can
>think of right off the bat is to simply go through each file
>char-by-char. If I encounter an open tag "<", I toggle to non-replace
>mode, and don't come back to replace mode until ">". While I'm in
>replace mode, I look for a sequence that matches what I'm trying to
>replace. If I find it, I remember that index and do a substr on it.
>Since tags don't nest within other tags, I figure this will work.
^^^^^^^^^^^^^^
That will work only "sometimes". But that might be "good enough"
for your purposes...
... in which case you can just do:
--------------------
{ # naked block for looping
if ( /\G(<[^>]*>)/gc ) {
print $1; # don't mess with tag contents
}
elsif ( /\G([^<]+)/gc ) {
my $str = $1;
$str =~ s/\bREPLACE\b/replaced/g;
print $str;
}
elsif ( /$/ ) {
last; # finished processing all chars in string
}
else {
warn 'huh? It should be impossible to get here (', pos(), ")\n";
last;
}
redo;
}
--------------------
or:
--------------------
foreach ( split /(<[^>]*>)/ ) {
if ( /^<[^>]*>$/ ) {
# do nothing if this chunk is a "tag"
}
else {
s/\bREPLACE\b/replaced/g;
}
print;
}
--------------------
Keeping in mind that both alternatives are a Dirty Hack, not Good Code.
If "REPLACE" is the string to be replaced, then it will not work
for any of the below snippets of perfectly valid HTML:
<!-- change it when it should be left alone -->
<img src="pic.jpg" alt=">>do not REPLACE me!<<">
^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^^^^^^^^^ attempt subst in this region
<!-- leave it alone when it should be changed -->
<p>If A < B then REPLACE the frobitz</p>
^^^^^
^^^^^ attempt subst in this region
Yet more examples in the answer to this Perl FAQ:
"How do I remove HTML from a string?"
but you have no doubt seen that already, since you checked the
Perl FAQ for questions mentioning "HTML" before you posted to
the Perl newsgroup.
>Is there another way to do it?
You should use one of the HTML parsing modules for parsing HTML.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sat, 23 Jun 2001 20:50:25 +0100
From: "John" <boxrec@uklinux.net>
Subject: Six degrees of separation
Message-Id: <9h2rvm$k9c$1@s1.uklinux.net>
Hi,
I'm hoping to write a script to find degrees of separation. Before I go away
and reinvent the wheel does anyone know if there is already a script or
module that does this (CPAN turned up 0). Also if anyone else is interested
in this let me know and I'll email you if/when it's finished.
Best wishes, John
------------------------------
Date: Sat, 23 Jun 2001 21:53:59 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: Six degrees of separation
Message-Id: <dX8H4crnHQN7Ewf0@gratiano.zephyr.org.uk>
In message <9h2rvm$k9c$1@s1.uklinux.net>, John <boxrec@uklinux.net>
writes
>I'm hoping to write a script to find degrees of separation. Before I go away
>and reinvent the wheel does anyone know if there is already a script or
>module that does this (CPAN turned up 0).
The Single Source Shortest Path implementation of Djikstra's algorithm
in Mastering Algorithms with Perl may be of use, if you consider each
edge to have a weight of 1, and connect everyone up in a graph that way.
--
James Coupe PGP Key: 0x5D623D5D
"You reinstall Dial-Up Networking. The Elf screams and becomes EBD690ECD7A1F
an icon. *** CONGRATULATIONS! *** You completed the BT Internet B457CA213D7E6
Helpdesk training course in 15 out of a possible 9000 moves." 68C3695D623D5D
------------------------------
Date: 23 Jun 2001 21:33:36 GMT
From: Ted Weston <ted9669@antijunk.yahoo.com>
Subject: Trouble checking params from a form
Message-Id: <9h31vg$h0c$1@comets.cs.swt.edu>
I'm processing input from a form, but I'm wondering
how to check that all params have been entered (ie,
no blanks, or incorrect entries). So far, I have:
#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
print header, start_html("Form"), h1("Example form");
if (param()) {
#do something ...
} else {
print hr();
print start_form();
#get params ...
print p(submit("order"), reset("clear"));
print end_form(), hr();
}
print end_html;
So now how can I check that these params are filled
in, let alone correctly (formatting, etc)?
Thanks for any help,
.ted
------------------------------
Date: Sat, 23 Jun 2001 21:33:31 +0100
From: "Richard" <richard@peterparkerDOTdemon.co.uk>
Subject: variables from cookie ?
Message-Id: <993328963.4720.0.nnrp-08.9e98fa2f@news.demon.co.uk>
Hi, new to perl, can anyone help with the following.
In a php page, I can call a variable from a cookie by using it's name (eg
$user)
How do you do that in a perl script (.cgi) ?
Thanks in advance.
------------------------------
Date: Sat, 23 Jun 2001 22:15:23 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Why does this split not work?
Message-Id: <3B351399.C42E29C4@rochester.rr.com>
Well, when you stepped over the problem line, did you first check to see
if $buf was undef or nonexistent? That's the point of using the
debugger. I seriously doubt that the problem is installation-specific.
--
Bob Walton
tuxy wrote:
>
> Hmm sounds like I found a perl problem. I tried -d and it fails with
> that message when I step over that line. I'll try to reduce the size f
> the file and try again. I'll also try another box to see if its some
> installation-specific problem.
>
> Thanks!
>
> Bob Walton wrote:
> >
> > tuxy wrote:
> > >
> > > I'm trying to split a pretty large buffer (>1000 lines) into sections
> > > based on a line that looks like
> > >
> > > NAME Jane Doe
> > >
> > > The file is a series of name-values like
> > >
> > > NAME Jane Doe
> > > AGE 21
> > > ADDRESS Anytown USA
> > > !
> > > NAME John Smith
> > > .
> > > .
> > >
> > > so I'm using something like
> > >
> > > my @people=split /^\s*NAME\s+/m,$buf;
> > >
> > > and I'm getting very odd results. It consistently fails with this
> > > message:
> > >
> > > Use of uninitialized value in split at datax.pm line 447, <IN> line
> > > 21 (#1)
> > >
> > > which I cannot comprehend. I checked perldoc perlfunc for split and
> > > didn't see anything that looked like this problem discussed. How could
> > > something be "uninitialized"? $buf is definitely initialized since I
> > > guess from the message it managed to get through 10 lines of it before
> > > it failed. What could be "uninitialized" at line 10? Even empty lines
> > > parse OK with /m.
> > >
> > > Another oddity- tweaking the code above this line (for unrelated tasks)
> > > CHANGES the line this fails at- sometimes it says <IN> line 2, line 10,
> > > 21, etc for the exact same input file. I looked at the file and see
> > > nothing unusual on any of those lines. I also turned on diagnostics and
> > > it didn't offer any further insight.
> > >
> > > By the way, the resultant array is one element which contains the entire
> > > buffer, even though there are many lines that meet the regex criteria.
> >
> > The regex and the split seem to work as you indicate you think it should
> > in my tests.
> >
> > The only way I can get your statement to fail with that message is for
> > $buf to be undefined. I suggest you put something like:
> >
> > die "Aha, buf is undef" unless defined $buf;
> >
> > just ahead of your problem statement and see if you get the die. If so,
> > check your code to see how $buf got undef'ed. Maybe perl -d would help.
> >
> > ...
> > --
> > 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 1181
***************************************