[15929] in Perl-Users-Digest
Perl-Users Digest, Issue: 3342 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jun 13 14:05:42 2000
Date: Tue, 13 Jun 2000 11:05:19 -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: <960919518-v9-i3342@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 13 Jun 2000 Volume: 9 Number: 3342
Today's topics:
Re: ANSI Perl: No Way !!! <aqumsieh@hyperchip.com>
Re: ANSI Perl: No Way !!! <blah@nospam.com>
Re: ANSI Perl: No Way !!! (Elaine -HFB- Ashton)
Re: ANSI Perl: No Way !!! (Bart Lateur)
Re: Attempting to parse malformed XML <gisle@ActiveState.com>
Re: Attempting to parse malformed XML <capps@solareclipse.net>
Re: Attempting to parse malformed XML <capps@solareclipse.net>
Re: Attempting to parse malformed XML <capps@solareclipse.net>
Re: Attempting to parse malformed XML <trevor@trevorsky.com>
Re: Beginner's mySQL Tutorial? <gellyfish@gellyfish.com>
Re: Beginner's mySQL Tutorial? <jeff@vpservices.com>
Re: Beginner's mySQL Tutorial? <dan@tuatha.sidhe.org>
Re: Can't open perl script <webmaster@navarone.com>
Can't split correctly! <raphaelp@nr1webresource.com>
Re: Can't split correctly! <uri@sysarch.com>
Re: Can't split correctly! <raphaelp@nr1webresource.com>
Re: Can't split correctly! <raphaelp@nr1webresource.com>
Re: Can't split correctly! (Eric Bohlman)
Re: Can't split correctly! <raphaelp@nr1webresource.com>
Re: Dumb question.. How to prompt the user and get the <mattking@techie.com>
Re: Dumb question.. How to prompt the user and get the <rootbeer@redcat.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Jun 2000 15:35:25 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: ANSI Perl: No Way !!!
Message-Id: <7asnuha91d.fsf@merlin.hyperchip.com>
bart.lateur@skynet.be (Bart Lateur) writes:
> And I distinctly remember having seen Bill Gates in an interview on TV,
> proclaiming that "Internet will never catch on." That must have been
> around 1997 (maybe 1996). Bill Gates tried to set up his own world wide
> network at the time (was that MSN? I think so). The U-turn came quite a
> bit later.
>
> Bill Gates said similar things about Linux, last year or so.
Wasn't he the one that said something like:
"I don't think anybody will ever need more than
64k of memory!"
which makes me laugh hysterically as I recall the minimum system
requirements needed to install any MS product!
And some people dare to call him a visionary and a pioneer! How
ignorant people can be!
--Ala
------------------------------
Date: Tue, 13 Jun 2000 17:41:56 +0200
From: Marco Natoni <blah@nospam.com>
Subject: Re: ANSI Perl: No Way !!!
Message-Id: <39465644.E103E752@nospam.com>
Ala,
Ala Qumsieh wrote:
> Wasn't he the one that said something like:
> "I don't think anybody will ever need more than
> 64k of memory!"
> which makes me laugh hysterically as I recall the minimum system
> requirements needed to install any MS product!
That is right: It is an undocumented feature, but if you type in the
string "Ok, now work like any other OS" when the SETUP.EXE program
requires your password, MS Windows 95 will run requiring only a 64 KB
long memory block. (And any component of the Office suite will do the
same.)
Obviously, the hardware vendor lobby had put pressure on Microsoft in
order to make this feature unknown. :)
> And some people dare to call him a visionary and a pioneer!
He really is that, believe me. ;)
Best regards,
Marco
------------------------------
Date: 13 Jun 2000 17:29:24 GMT
From: elaine@chaos.wustl.edu (Elaine -HFB- Ashton)
Subject: Re: ANSI Perl: No Way !!!
Message-Id: <slrn8kcrsh.cfd.elaine@chaos.wustl.edu>
In article <7asnuha91d.fsf@merlin.hyperchip.com>, Ala Qumsieh wrote:
>
>And some people dare to call him a visionary and a pioneer! How
>ignorant people can be!
He's didn't need to be right to laugh all the way to the bank now.
Lots of people throughout history have been made to eat their words.
e.
------------------------------
Date: Tue, 13 Jun 2000 17:52:04 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: ANSI Perl: No Way !!!
Message-Id: <394673c9.7276409@news.skynet.be>
Ala Qumsieh wrote:
>> Bill Gates said similar things about Linux, last year or so.
>
>Wasn't he the one that said something like:
>
> "I don't think anybody will ever need more than
> 64k of memory!"
>
>which makes me laugh hysterically as I recall the minimum system
>requirements needed to install any MS product!
Wrong by a factor of 10.
"640k is enough for anybody."
Note that the 8086 and 8088 could only address 1Mb, in chunks of 64k, so
the PC-XT was built around that limitation. 384k (= 128k x 3) was
reserved for direct memory access to the video memory, so changing one
byte in that range would make one character on screen change shape.
Fixed pitch characters, of course. The remainder, 640k, was available
for program memory -- including the OS. BG said that this ought to be
enough.
--
Bart.
------------------------------
Date: 13 Jun 2000 18:41:16 +0200
From: Gisle Aas <gisle@ActiveState.com>
Subject: Re: Attempting to parse malformed XML
Message-Id: <m31z21355f.fsf@eik.g.aas.no>
Charles Capps <capps@solareclipse.net> writes:
> The only form of exported data is XML. The XML that it produces has
> *CERTAIN* tag elements unquoted. Example:
> <message body="Laa dee daa" number=000001 author="Lame dude">
>
> Unfortunately, nothing will parse it. Expat (XML::Parser, etc) chokes and
> dies when it comes across the unquoted elements.
You might want try to use HTML::Parser on it.
--
Gisle Aas
------------------------------
Date: Tue, 13 Jun 2000 09:53:48 -0700
From: Charles Capps <capps@solareclipse.net>
Subject: Re: Attempting to parse malformed XML
Message-Id: <3946671C.9E87C515@solareclipse.net>
Eric Bohlman wrote:
>
> Charles Capps (capps@solareclipse.net) wrote:
> : I've been given the job of taking exported data from a certain extremely
> : brain-damaged and poorly designed application and rewriting it into a format
> : that an in-house application can read.
> :
> : The only form of exported data is XML. The XML that it produces has
> : *CERTAIN* tag elements unquoted. Example:
> : <message body="Laa dee daa" number=000001 author="Lame dude">
>
> You mean "attributes unquoted" (in cases like this, it's important to get
> the terminology right).
At least I didn't call them dohickeys. Thanks for the clarification. :)
> : Unfortunately, nothing will parse it. Expat (XML::Parser, etc) chokes and
> : dies when it comes across the unquoted elements.
>
> Yes, as an XML parser is not allowed to continue parsing after
> encountering illegal syntax. However, that does *not* mean that the
> program that called the parser must cease executing when the parsing
> fails; if you wrap the call to the parser in an eval{} block, you can
> catch the error message the parser issued when it gave up, which will
> include information about where in the data the problem occurred. You can
> use that information to fix the data (in this case, by inserting a quote
> and using a regex to find out where to insert the closing quote), and then
> try reparsing the data (i.e. creating a new parser and calling it).
I really hadn't thought of that... I'll have to tinker. thanks...
> If the *only* well-formedness violations in your data are of this sort,
> this strategy will work well because the parser will always be reporting
> errors at exactly the point where the mistake was made. Other types of
> violations can't easily be corrected this way because the parser won't be
> able to tell that the input doesn't make sense until some point past
> where the error occurred (just as perl can't tell you that you're missing
> a closing brace until it reaches the end of the program).
>
> : I'm very reluctant to attempt to write my own parsing routine. I'm currently
> : using a series of regexes to split apart the tag, but it's difficult, tedious
> : work due to the randomness of the element locations, values, and lengths, as
> : well as tags.
>
> The method I've outlined will greatly limit the amount of hack-parsing
> you need to do, since it relies on the parser to find the problems.
Great. Thanks again. :)
--
CC
------------------------------
Date: Tue, 13 Jun 2000 10:03:20 -0700
From: Charles Capps <capps@solareclipse.net>
Subject: Re: Attempting to parse malformed XML
Message-Id: <39466958.9029A95C@solareclipse.net>
Tad McClellan wrote:
>
> On Tue, 13 Jun 2000 01:50:12 -0700, Charles Capps <capps@solareclipse.net> wrote:
> >I've been given the job of taking exported data from a certain extremely
> >brain-damaged and poorly designed application and rewriting it into a format
> >that an in-house application can read.
> >
> >The only form of exported data is XML.
>
> No it isn't.
For this app, it is. It stores everything else in some absolutely
indecipherable compressed data files... I'd rather parse this than that.
> >The XML that it produces has
> >*CERTAIN* tag elements unquoted. Example:
> ><message body="Laa dee daa" number=000001 author="Lame dude">
>
> That is not XML. Quoting attributes is _required_ by XML.
>
> If the attributes are not quoted, then the data is not XML.
I told ya the app is severely brain damaged... :(
One more reason to tell the boss it sucks.
> The only form of exported data is "some angle-brackety text
> that sorta kinda looks like XML".
*LOL* Can I quote you on that?
> You are allowed to leave off the quotes in _SGML_, but that
> is subject to restrictions of the form of the value, and
> your "number" attribute value does not conform to the
> restrictions, so you don't have SGML either.
That throws the brief idea of using an SGML parser out the window also...
> ( the value must start with a _name start character_. Digits
> are not name start characters.
> )
>
> >Unfortunately, nothing will parse it.
>
> If you can identify what the data is, you may be able to find
> a program that can parse it.
>
> So far we only know what it _isn't_ :-(
Exactly. :(
> >I'm currently
> >using a series of regexes to split apart the tag, but it's difficult, tedious
> >work due to the randomness of the element locations, values, and lengths, as
> >well as tags.
>
> It (using regexs rather than a real parser with a stack) is
> also impossible.
Actually, I've had limited success... it's just a real pita to extract data
without sometimes accidentally siphoning in the next element.
> You should use a parser for parsing (though that too is impossible
> if you cannot identify what format the data is in).
Yup.
> >Does anyone have any recommendations, pointers, hints, URLs, or
> >perldoc/manpages? ;)
> >
> >(Sigh, why can't this be like LAST week's XML project! That was easy once I
> >found the documentation. Blech!)
>
> Things are easier when they follow standards.
You're telling me? ;)
> All you need to do is identify what standard the data follows
> (though I expect you may find that it does not follow any
> standard...)
Considering the rest of the program, it's very likely that they pulled it out
of nowhere...
> 1 while s/(<[^>]*? [a-zA-Z][a-zA-Z0-9.-]*\s*=)([^"> ]+)/$1"$2"/;
>
> This may work for some (or many) cases, but can still end
> up doing the wrong thing...
That looks right... Though I believe there are element names that use
underscores, which is only sticking one more character in. I'll see if it
works and report back.
Thanks!
--
CC
------------------------------
Date: Tue, 13 Jun 2000 10:05:19 -0700
From: Charles Capps <capps@solareclipse.net>
Subject: Re: Attempting to parse malformed XML
Message-Id: <394669CF.7F83BF2F@solareclipse.net>
Gisle Aas wrote:
>
> Charles Capps <capps@solareclipse.net> writes:
>
> > The only form of exported data is XML. The XML that it produces has
> > *CERTAIN* tag elements unquoted. Example:
> > <message body="Laa dee daa" number=000001 author="Lame dude">
> >
> > Unfortunately, nothing will parse it. Expat (XML::Parser, etc) chokes and
> > dies when it comes across the unquoted elements.
>
> You might want try to use HTML::Parser on it.
>
> --
> Gisle Aas
Now that's an interesting thought... Tad McClellan mentioned that this stuff
was more like SGML than XML, but it's poorly formed SGML to boot. HTML is
definitely poorly formed SGML. (*LOL*) I'll give this idea a try as well.
Thanks!
--
CC
------------------------------
Date: Tue, 13 Jun 2000 10:19:08 -0700
From: "Trevor Sky Garside" <trevor@trevorsky.com>
Subject: Re: Attempting to parse malformed XML
Message-Id: <e0u15.6598$PZ5.169660@nntp3.onemain.com>
Just an idea here...
The data you are getting *looks* like XML, apart from the occasionally left
off quotes, right?
Well, why don't you toss each line into a RE that corrects that small
oversight... something that does something like this:
=~ s/ (\w.*?)=(\w.*?)([\s>])/ $1="$2"$3/;
Now, I just threw that together, and I might have munged my RegEx logic, but
I think that would take care of it, assuming the unquoted elements do not
contain spaces (it would be VERY bad if they did anyways).
Let me know if that helps you out.
--Trevor
"Charles Capps" <capps@solareclipse.net> wrote in message
news:3945F5C4.750FC54@solareclipse.net...
> I've been given the job of taking exported data from a certain extremely
> brain-damaged and poorly designed application and rewriting it into a
format
> that an in-house application can read.
>
> The only form of exported data is XML. The XML that it produces has
> *CERTAIN* tag elements unquoted. Example:
> <message body="Laa dee daa" number=000001 author="Lame dude">
>
> Unfortunately, nothing will parse it. Expat (XML::Parser, etc) chokes and
> dies when it comes across the unquoted elements.
>
> I'm very reluctant to attempt to write my own parsing routine. I'm
currently
> using a series of regexes to split apart the tag, but it's difficult,
tedious
> work due to the randomness of the element locations, values, and lengths,
as
> well as tags.
>
> Does anyone have any recommendations, pointers, hints, URLs, or
> perldoc/manpages? ;)
>
> (Sigh, why can't this be like LAST week's XML project! That was easy once
I
> found the documentation. Blech!)
> --
> Charles Capps
------------------------------
Date: Tue, 13 Jun 2000 15:16:33 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Beginner's mySQL Tutorial?
Message-Id: <lfs15.239$82.29129@news.dircon.co.uk>
On Tue, 13 Jun 2000 18:18:39 +1000, Robert Chalmers Wrote:
> "Mark-Jason Dominus" <mjd@plover.com> wrote in message
> news:39452500.4786$2fb@news.op.net...
>> In article <8i2ojk$c9m$1@news.online.de>,
>> Raphael Pirker <raphaelp@nr1webresource.com> wrote:
>> >Hi,
>> >
>> >i'm looking for a tutorial that will teach me how to search data in
>> >an mySQL database, implement them into my scripts and read all the
>> >data into variables. Any links?
>>
>> You might want to look at:
>>
>> http://www.perl.com/pub/1999/10/DBI.html
>
>
>
> I guess this whole thread means that you cant simply use Perl to talk to
> MySql - you have to use something like the DBI thing?
>
I'm not quite what you mean - are you expecting to have built in support
fo MySQL ? What if I want to use Informix or Oracle.
/J\
------------------------------
Date: Tue, 13 Jun 2000 08:37:42 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Beginner's mySQL Tutorial?
Message-Id: <39465546.CE984EAE@vpservices.com>
Robert Chalmers wrote:
>
> I guess this whole thread means that you cant simply use Perl to talk to
> MySql - you have to use something like the DBI thing?
That is kind of like saying "You can't use English to talk about
baseball, you have to use verbs and nouns." DBI is part of Perl. It is
the part of Perl that is pre-designed to talk to many kinds of
databases. Can you ignore DBI and reinvent the wheel to talk to those
databases, sure, if you want to. Are there other non-DBI Perl methods
for talking to databases, yes, but not ones that have anything like the
portability and support that DBI has.
--
Jeff
------------------------------
Date: Tue, 13 Jun 2000 16:35:52 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Beginner's mySQL Tutorial?
Message-Id: <Ipt15.767$My2.2605@news1.rdc1.ct.home.com>
Robert Chalmers <robert@chalmers.com.au> wrote:
> I guess this whole thread means that you cant simply use Perl to talk to
> MySql - you have to use something like the DBI thing?
DBI, accompanied by the DBD::MySQL module, *is* how perl talks to
MySQL...
> "Mark-Jason Dominus" <mjd@plover.com> wrote in message
> news:39452500.4786$2fb@news.op.net...
>> In article <8i2ojk$c9m$1@news.online.de>,
>> Raphael Pirker <raphaelp@nr1webresource.com> wrote:
>> >Hi,
>> >
>> >i'm looking for a tutorial that will teach me how to search data in an
> mySQL
>> >database, implement them into my scripts and read all the data into
>> >variables. Any links?
>>
>> You might want to look at:
>>
>> http://www.perl.com/pub/1999/10/DBI.html
------------------------------
Date: Tue, 13 Jun 2000 09:02:09 -0700
From: "Roger Brown" <webmaster@navarone.com>
Subject: Re: Can't open perl script
Message-Id: <l2t15.6691$k2U.50790789@news.randori.com>
Thanks, Rodney. Typing "perl example.pl" worked. I thought for sure I
tried that. Guess not.
Rodney Engdahl <red_orc@my-deja.com> wrote in message
news:8i5bea$sl6$1@nnrp1.deja.com...
> In article <jSc15.2521$k2U.9109742@news.randori.com>,
> "Roger Brown" <webmaster@navarone.com> wrote:
>
> > Now, the dos command, still in the ~eg sub-dir, I receive the response
> > "Can't open perl script "example": No such file or directory". The
> > example.pl is still there. I have copied it to perl\bin and tried
> > there; same result. It's as though perl.exe is looking
> > for "example.pl" in a place where it doesn't exist instead of looking
> > under its own nose. BUT...
> >
> > When I dbl-click example.pl from the explorer, I can see the dos
> > window display the "Hello, etc." properly.
>
> if the file name is example.pl, you need to tell that to perl:
>
> perl example.pl
>
> looks like the file got renamed with a .pl extension.
>
> >
> > Anyone have any ideas what I have done wrong and how to fix it?
> >
> > Thanks in advance for all who read and or respond to this
> > post/question.
> >
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Tue, 13 Jun 2000 18:07:37 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Can't split correctly!
Message-Id: <8i5m9f$jv1$1@news.online.de>
I have the following code and even though the Form Fields "name", "email"
and "address" are not defined or are blank, the subroutine "error_require"
is never executed! Any help would be very much appreciated!
$required = "name, email, address"
# Remove Spaces and Line-Breaks
$required =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
$required =~ s/(\s+)?\n+(\s+)?//g;
# Split $required into different variables
@Required = split(/,/,$required);
foreach $require (@Required) {
if ($FORM{$require} eq undef) {
&error_require;
}
elsif ($FORM{$require} eq "") {
&error_require;
}
}
TIA,
Raphael
------------------------------
Date: Tue, 13 Jun 2000 16:18:15 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Can't split correctly!
Message-Id: <x7d7ll8shn.fsf@home.sysarch.com>
>>>>> "RP" == Raphael Pirker <raphaelp@nr1webresource.com> writes:
RP> I have the following code and even though the Form Fields "name", "email"
RP> and "address" are not defined or are blank, the subroutine "error_require"
RP> is never executed! Any help would be very much appreciated!
RP> $required = "name, email, address"
RP> # Remove Spaces and Line-Breaks
RP> $required =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
^^^ ^^^
those make no sense. \s includes \n so \s+ will match and \n never will
and you don't need grouping there. this is much simpler:
$required =~ s/\s*,\s*/,/g ;
RP> $required =~ s/(\s+)?\n+(\s+)?//g;
again, that can be simplified:
$required =~ s/\s*\n+\s*//g;
RP> # Split $required into different variables
RP> @Required = split(/,/,$required);
RP> foreach $require (@Required) {
RP> if ($FORM{$require} eq undef) {
eq undef is wrong. undef is not a string. if you ran with -w it would
have told you this. you test for undef with the defined function.
if ( defined( $FORM{$require} ) {
better yet is to test with exists (assuming %FORM is filled out
correctly). you should be using CGI.pm for this anyway and i bet you aren't.
RP> &error_require;
RP> }
RP> elsif ($FORM{$require} eq "") {
why are you testing for undefined AND blank? an empty field is not
usually sent.
just wait until moronzilla gets a hold of this. she will fix it
fine. :-)
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page ----------- http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net ---------- http://www.northernlight.com
------------------------------
Date: Tue, 13 Jun 2000 18:35:28 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: Can't split correctly!
Message-Id: <8i5nt6$kne$1@news.online.de>
> those make no sense. \s includes \n so \s+ will match and \n never will
> and you don't need grouping there. this is much simpler:
>
> $required =~ s/\s*,\s*/,/g ;
shows even Matt Wright can be wrong... (the code-snippled was taken of the
"famous" FormMailer.pl) :-)
> why are you testing for undefined AND blank? an empty field is not
> usually sent.
Because if the user just fills in a space into the field, that space will be
removed with the "space-remover" and all we have is a blank field...
Thanks for your corrections. I will take them into consideration and tell
you if they worked!
Uri Guttman <uri@sysarch.com> wrote in message
news:x7d7ll8shn.fsf@home.sysarch.com...
> >>>>> "RP" == Raphael Pirker <raphaelp@nr1webresource.com> writes:
>
> RP> I have the following code and even though the Form Fields "name",
"email"
> RP> and "address" are not defined or are blank, the subroutine
"error_require"
> RP> is never executed! Any help would be very much appreciated!
>
> RP> $required = "name, email, address"
>
> RP> # Remove Spaces and Line-Breaks
> RP> $required =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
> ^^^ ^^^
>
> those make no sense. \s includes \n so \s+ will match and \n never will
> and you don't need grouping there. this is much simpler:
>
> $required =~ s/\s*,\s*/,/g ;
>
> RP> $required =~ s/(\s+)?\n+(\s+)?//g;
>
> again, that can be simplified:
>
> $required =~ s/\s*\n+\s*//g;
>
> RP> # Split $required into different variables
> RP> @Required = split(/,/,$required);
>
> RP> foreach $require (@Required) {
> RP> if ($FORM{$require} eq undef) {
>
> eq undef is wrong. undef is not a string. if you ran with -w it would
> have told you this. you test for undef with the defined function.
>
> if ( defined( $FORM{$require} ) {
>
> better yet is to test with exists (assuming %FORM is filled out
> correctly). you should be using CGI.pm for this anyway and i bet you
aren't.
>
> RP> &error_require;
> RP> }
> RP> elsif ($FORM{$require} eq "") {
>
> why are you testing for undefined AND blank? an empty field is not
> usually sent.
>
> just wait until moronzilla gets a hold of this. she will fix it
> fine. :-)
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ----------
http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX
Consulting
> The Perl Books Page -----------
http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net ----------
http://www.northernlight.com
------------------------------
Date: Tue, 13 Jun 2000 18:40:36 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: Can't split correctly!
Message-Id: <8i5o9s$ks9$1@news.online.de>
Now the code looks like this, but still no luck!
$required = "name, email, address";
# Remove Spaces and Line-Breaks
$required =~ s/\s*,\s*/,/g;
$required =~ s/\s*\n+\s*//g;
# Split $required into different variables
@Required = split(/,/,$required);
foreach $require (@Required) {
if ( !defined( $FORM{$require} ) ) {
&error_require;
}
elsif ($FORM{$require} eq "") {
&error_require;
}
}
Uri Guttman <uri@sysarch.com> wrote in message
news:x7d7ll8shn.fsf@home.sysarch.com...
> >>>>> "RP" == Raphael Pirker <raphaelp@nr1webresource.com> writes:
>
> RP> I have the following code and even though the Form Fields "name",
"email"
> RP> and "address" are not defined or are blank, the subroutine
"error_require"
> RP> is never executed! Any help would be very much appreciated!
>
> RP> $required = "name, email, address"
>
> RP> # Remove Spaces and Line-Breaks
> RP> $required =~ s/(\s+|\n)?,(\s+|\n)?/,/g;
> ^^^ ^^^
>
> those make no sense. \s includes \n so \s+ will match and \n never will
> and you don't need grouping there. this is much simpler:
>
> $required =~ s/\s*,\s*/,/g ;
>
> RP> $required =~ s/(\s+)?\n+(\s+)?//g;
>
> again, that can be simplified:
>
> $required =~ s/\s*\n+\s*//g;
>
> RP> # Split $required into different variables
> RP> @Required = split(/,/,$required);
>
> RP> foreach $require (@Required) {
> RP> if ($FORM{$require} eq undef) {
>
> eq undef is wrong. undef is not a string. if you ran with -w it would
> have told you this. you test for undef with the defined function.
>
> if ( defined( $FORM{$require} ) {
>
> better yet is to test with exists (assuming %FORM is filled out
> correctly). you should be using CGI.pm for this anyway and i bet you
aren't.
>
> RP> &error_require;
> RP> }
> RP> elsif ($FORM{$require} eq "") {
>
> why are you testing for undefined AND blank? an empty field is not
> usually sent.
>
> just wait until moronzilla gets a hold of this. she will fix it
> fine. :-)
>
> uri
>
> --
> Uri Guttman --------- uri@sysarch.com ----------
http://www.sysarch.com
> SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX
Consulting
> The Perl Books Page -----------
http://www.sysarch.com/cgi-bin/perl_books
> The Best Search Engine on the Net ----------
http://www.northernlight.com
------------------------------
Date: 13 Jun 2000 17:15:53 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Can't split correctly!
Message-Id: <8i5q89$eel$7@nntp9.atl.mindspring.net>
Raphael Pirker (raphaelp@nr1webresource.com) wrote:
: Now the code looks like this, but still no luck!
: $required = "name, email, address";
:
: # Remove Spaces and Line-Breaks
: $required =~ s/\s*,\s*/,/g;
: $required =~ s/\s*\n+\s*//g;
:
: # Split $required into different variables
: @Required = split(/,/,$required);
:
: foreach $require (@Required) {
At this point, I'd suggest you put in some temporary print statements to
see what you've actually got:
print "Field [$require] = [$FORM{$require}]\n";
Note the brackets, intended to make any extra whitespace visible.
: if ( !defined( $FORM{$require} ) ) {
: &error_require;
: }
: elsif ($FORM{$require} eq "") {
: &error_require;
: }
: }
In this case, a single logical expression rather than a chain of tests
would make your code more readable:
if (!defined($FORM{$require}) or $FORM{$require} eq "") {
&error_require;
}
which in turn could be expressed more idiomatically as:
&error_require if !defined $FORM{$require} or $FORM{$require} eq "";
P.S. Note how I quoted portions of your original, interspersed with my
replies, rather than making some remarks and quoting the entire original
below them. This makes it easier to follow the discussion.
------------------------------
Date: Tue, 13 Jun 2000 19:34:22 +0200
From: "Raphael Pirker" <raphaelp@nr1webresource.com>
Subject: Re: Can't split correctly!
Message-Id: <8i5rbs$mgs$1@news.online.de>
> print "Field [$require] = [$FORM{$require}]\n";
It returned [] = []...?
Anyway, I rechecked and noticed an error in the typing at this line:
$require(d) = $FORM{require(d)};
I had forgotten the d, which then mucked up the code, as there was nothing
to split, etc...
Now, everything works just fine!
Thanks a lot for that "print" trick!
Regards,
Raphael
PS: Considered your notice about quoting posts!
------------------------------
Date: Tue, 13 Jun 2000 17:22:18 +0200
From: "Matt King" <mattking@techie.com>
Subject: Re: Dumb question.. How to prompt the user and get the input.
Message-Id: <8i5jk0$1d0i$1@news2atm.raleigh.ibm.com>
Abe Timmerman <abe@ztreet.demon.nl> wrote in message
news:css1kso7dkv4hi8erjpm53i39hq85tha9b@4ax.com...
> I am surprised. when I do:
> perldoc -f getc
> I get:
> getc FILEHANDLE
> getc Returns the next character from the input file attached to
> FILEHANDLE, or the undefined value at end of file, or if
> there was an error. If FILEHANDLE is omitted, reads from
> STDIN. This is not particularly efficient. However, it
> cannot be used by itself to fetch single characters without
> waiting for the user to hit enter.
Yes, after I posted that I found out that it still waits for an enter before
continuing...... However, I do not get any errors from Perl on this. So,
without using any ad-ins, how can I get a single key stroke with Active Perl
on a Windows platform? I could do a system call to DOS with a pause > nul
command, but that's not the way I really want to do it. What I'm really
looking for is the equivalent to the C's getch() command. The script will do
nothing with the entered key stroke. It's just used to pause the script
until the user wishes to continue.
Matt
------------------------------
Date: Tue, 13 Jun 2000 08:38:46 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Dumb question.. How to prompt the user and get the input.
Message-Id: <Pine.GSO.4.10.10006130837500.18837-100000@user2.teleport.com>
On Tue, 13 Jun 2000, Matt King wrote:
> without using any ad-ins, how can I get a single key stroke with
> Active Perl on a Windows platform?
Does section five of the FAQ answer your question? Some of the suggested
ways use add-ons, but no ad-ins! :-)
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
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 3342
**************************************