Click here to get back home

re: use of DBI; I am getting multiple error messages mixed in with the correct output.

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
re: use of DBI; I am getting multiple error messages mixed in with the correct output. Ted 04-23-2008
Get Chitika Premium
Posted by Joost Diepenmaat on April 24, 2008, 9:45 am
Please log in for more thread options

> But this still seems quite different to what NULL means in SQL. How
> would you explain the rationale for that mapping? Abigail has already
> explained the reason for my surprise at this.

I think that undef is a good choice for NULL if you want to map SQL
values to "native" perl values. undef is /conceptually/ the closest perl
has to SQL NULL.

If on the other hand, you want values that /behave/ like their SQL
counterparts, that would mean that most values would behave differently
from the built-in perl types. And that would make it much more
cumbersome to use data from the database in perl code that doesn't
expect that behaviour (which would be almost all reusable code).

It would probably not be too much work to wrap DBI to return a special
NULL object instead of undef, for example, but I think the current
mapping makes the most sense for a relatively low-level interface like
DBI.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/

Posted by Abigail on April 24, 2008, 9:55 am
Please log in for more thread options
_
Joost Diepenmaat (joost@zeekat.nl) wrote on VCCCL September MCMXCIII in
^^
^^ > But this still seems quite different to what NULL means in SQL. How
^^ > would you explain the rationale for that mapping? Abigail has already
^^ > explained the reason for my surprise at this.
^^
^^ I think that undef is a good choice for NULL if you want to map SQL
^^ values to "native" perl values. undef is /conceptually/ the closest perl
^^ has to SQL NULL.

No, 'undef' is a compromise. When using numbers, and numerical operators,
NaN is much closer to an SQL NULL than undef is. However, Perl has only
typed values, and mixes and matches strings and numbers without explicite
casting. And there isn't a string alternative for NaN.

^^ If on the other hand, you want values that /behave/ like their SQL
^^ counterparts, that would mean that most values would behave differently
^^ from the built-in perl types. And that would make it much more
^^ cumbersome to use data from the database in perl code that doesn't
^^ expect that behaviour (which would be almost all reusable code).

Really? I claim that good code, that is, code that uses warnings, will
have to deal with 'undef's explicite anyway, because most operators will
issue a warning if one or more of their arguments is undefined anyway.

^^ It would probably not be too much work to wrap DBI to return a special
^^ NULL object instead of undef, for example, but I think the current
^^ mapping makes the most sense for a relatively low-level interface like
^^ DBI.


Abigail
--
perl -wle 'eval {die [[qq [Just another Perl Hacker]]]};; print
$}[$#}}]}[$#}}[$#}}]}]'

Posted by Ben Bullock on April 24, 2008, 6:57 am
Please log in for more thread options
On Wed, 23 Apr 2008 21:52:51 -0700, Ted wrote:

> On page 155, about half way down the page talking about the
> function defined, I see "A scalar that contains no valid string,
> numeric, or reference value is known as the undefined value, or undef
> for short. Many operations return the undefined value ender exceptional
> conditions, such as end of file, uninitialized variable, system error,
> and such. This function allows you to distinguish between an undefined
> null string and a defined null string when you're using operators that
> might return a real null string."

Try running the following script to clarify what this means:

#!/usr/bin/perl
use warnings;
use strict;
my $a;
my $b = "";
print "a is defined\n" if defined($a);
print "b is defined\n" if defined($b);

Here $b is a "real null string" and $a is undefined.

> Here you're confusing me. I agree, given what Wall et al. wrote about
> it, comparing undefined to null in Java or C/C++ is a decent analogy,
> but not exact. It is more correct to relate it to variables or
> identifiers that have been declared but not yet initialized.

That's not a good analogy. Again, try the following script:

#!/usr/bin/perl
use warnings;
use strict;
my $b = "";
print "1: b is defined\n" if defined($b);
undef ($b);
print "2: b is defined\n" if defined($b);

The undefined value in Perl is assigned to variables but that doesn't
mean that undefined equals uninitialized.

> Allowing a programming
> language to be markedly multivocal is a recipe for confusion, at least
> without extensive and pedantic documentation.

Well, you're going to be confused then - if you feel that way, maybe it's
better not to learn Perl.

> But ALL of these concepts are very different from the idea of NULL in
> SQL. For example, The book, from Osborne, "SQL: The complete reference"
> by James Groff and Paul Weinberg, described it as referring to data that
> is missing, unknown, or don't apply.

Which seems to be exactly what the undefined value in Perl is, to me.

> While NULL in SQL is different from
> numeric or string data, I see nothing in the idea that indicates it is a
> value that is not part of the normal range of values.

Perhaps you can think of Perl's undef as being part of the normal range
of values, too.

> I see nothing similar between the idea of NULL in SQL and either null or
> undefined in the other languages.

That's odd, because the more you talk about SQL's NULL, the more it looks
like Perl's undefined value to me.

> But if you see the idea of the empty set as being integral to the
> idea of null as it exists in SQL, then the relation with either null or
> undefined in C++, Java or Perl becomes even more distant because the
> relevant containers in C++ and Java make no direct use of nulls in
> handling empty sets as far as I can see.

You seem to be getting lost in your own verbosity here - you start this
sentence including Perl and by the end of it you are only talking about
C++ and Java.

> In both cases, the containers
> have member functions that return true if the set is empty and fals
> otherwise.

But now, as far as I can figure out, you're not talking about Perl any
more anyway.


Posted by Ted on April 24, 2008, 8:48 am
Please log in for more thread options
> On Wed, 23 Apr 2008 21:52:51 -0700, Ted wrote:
> > On page 155, about half way down the page talking about the
> > function defined, I see "A scalar that contains no valid string,
> > numeric, or reference value is known as the undefined value, or undef
> > for short. =A0Many operations return the undefined value ender exception=
al
> > conditions, such as end of file, uninitialized variable, system error,
> > and such. =A0This function allows you to distinguish between an undefine=
d
> > null string and a defined null string when you're using operators that
> > might return a real null string."
>
> Try running the following script to clarify what this means:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $a;
> my $b =3D "";
> print "a is defined\n" if defined($a);
> print "b is defined\n" if defined($b);
>
> Here $b is a "real null string" and $a is undefined.
>
No. $b holds an empty string, and empty strings are not the same thing
as NULL (as defined in either C++ and Java or SQL).

> > Here you're confusing me. =A0I agree, given what Wall et al. wrote about=

> > it, comparing undefined to null in Java or C/C++ is a decent analogy,
> > but not exact. =A0It is more correct to relate it to variables or
> > identifiers that have been declared but not yet initialized.
>
> That's not a good analogy. Again, try the following script:
>
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $b =3D "";
> print "1: b is defined\n" if defined($b);
> undef ($b);
> print "2: b is defined\n" if defined($b);
>
> The undefined value in Perl is assigned to variables but that doesn't
> mean that undefined equals uninitialized.
>
But that is exactly what Wall et al. said about undefined. I learned
much of what I know about Perl from their book, and they said that an
undefined variable is one that does not have a valid string, number or
reference, and that exactly describes a variable that has not yet been
initialized. The empty string is a valid string in all of the
languages I use, and it means something quite different from a SQL
null.

> > Allowing a programming
> > language to be markedly multivocal is a recipe for confusion, at least
> > without extensive and pedantic documentation.
>
> Well, you're going to be confused then - if you feel that way, maybe it's
> better not to learn Perl.
>
Why? Most of what I have seen about perl seems quite well defined.

> > But ALL of these concepts are very different from the idea of NULL in
> > SQL. =A0For example, The book, from Osborne, "SQL: The complete referenc=
e"
> > by James Groff and Paul Weinberg, described it as referring to data that=

> > is missing, unknown, or don't apply.
>
> Which seems to be exactly what the undefined value in Perl is, to me.
>
Then you're using a definition of the term that is quite different
from what Wall et al. wrote about undefined. Where they wrong, or
merely misleading?

> > While NULL in SQL is different from
> > numeric or string data, I see nothing in the idea that indicates it is a=

> > value that is not part of the normal range of values.
>
> Perhaps you can think of Perl's undef as being part of the normal range
> of values, too.
>
In principal I'd have no problem with that, if it weren't for the fact
that Wall et al. described them as referring to variables that were
not initialized. That is, if Perl's undef could be equated to SQL's
concept of null. But as Abigail pointed out, that equation would be
problmatic at best.

> > I see nothing similar between the idea of NULL in SQL and either null or=

> > undefined in the other languages.
>
> That's odd, because the more you talk about SQL's NULL, the more it looks
> like Perl's undefined value to me.
>
Until now, I had seen nothing written about perl that suggested that
Wall et al.'s description of undefined meant anything other than a
reference to variables that had not yet been initialized, and that is
a very different concept from SQL's NULL.

> > But if you see the idea of the empty set as being integral to the
> > idea of null as it exists in SQL, then the relation with either null or
> > undefined in C++, Java or Perl becomes even more distant because the
> > relevant containers in C++ and Java make no direct use of nulls in
> > handling empty sets as far as I can see.
>
> You seem to be getting lost in your own verbosity here - you start this
> sentence including Perl and by the end of it you are only talking about
> C++ and Java.
>
This was merely a response to Martien's reference to set theoretic
operations. He'd expressed uncertainty about support C++ and Java
provide for them and implied support for them implied a handling of
SQL nulls in a manner similar to how Perl handles undef.

> > =A0In both cases, the containers
> > have member functions that return true if the set is empty and fals
> > otherwise.
>
> But now, as far as I can figure out, you're not talking about Perl any
> more anyway.

This too was merely a response to Martien's reference to set theoretic
operations. In particular, it is an explanation of how it is done in
those two languages.

Why would you object to my leveraging what I know in other languages
to learn Perl? I have routinely used a student's or colleague's
knowledge of one programming language to more quickly learn another
they needed but had not yet started to study. In my experience, using
similarities and differences between languages a student knows and the
one(s) he is trying to learn greatly accelerates his learning (but it
depends on the instructor or mentor knowing both very well).

Ted


Posted by Ben Bullock on April 24, 2008, 10:10 am
Please log in for more thread options

>> Try running the following script to clarify what this means:
>>
>> #!/usr/bin/perl
>> use warnings;
>> use strict;
>> my $a;
>> my $b = "";
>> print "a is defined\n" if defined($a);
>> print "b is defined\n" if defined($b);
>>
>> Here $b is a "real null string" and $a is undefined.

Excuse me, this should say '$b is a "defined null string"' not "real".

> No. $b holds an empty string, and empty strings are not the same thing
> as NULL (as defined in either C++ and Java or SQL).

But I'm not talking about C++ or Java or SQL. I'm talking about
Perl. This is a perl newsgroup. "" is what the book you're referring
to means by a "defined null string", as opposed to an undefined value.

> But that is exactly what Wall et al. said about undefined. I learned
> much of what I know about Perl from their book, and they said that an
> undefined variable is one that does not have a valid string, number or
> reference, and that exactly describes a variable that has not yet been
> initialized. The empty string is a valid string in all of the
> languages I use, and it means something quite different from a SQL
> null.

We're not talking about the empty string any more, the above is
talking about an undefined value. As I pointed out in the two scripts,
$b="" and $b=undef are two totally different things.

>> > But ALL of these concepts are very different from the idea of NULL in
>> > SQL.  For example, The book, from Osborne, "SQL: The complete reference"
>> > by James Groff and Paul Weinberg, described it as referring to data that
>> > is missing, unknown, or don't apply.
>>
>> Which seems to be exactly what the undefined value in Perl is, to me.
>>
> Then you're using a definition of the term that is quite different
> from what Wall et al. wrote about undefined. Where they wrong, or
> merely misleading?

Look at this kind of example:

my @arr = (undef, 1, 3, undef, 4);

If you then refer to $arr[3] you get the undefined value. So you can
assign it into a variable. What is more you can do things like

(undef, $x, $y) = @z;

to ignore the value of $z[0].

I don't know how that compares to SQL's NULL in detail, but it seems
to me that this refers to data that is "missing, unknown or does not
apply", thus from your statement this "seems to be exactly what the
undefined value in Perl is, to me", as I said.

>> > While NULL in SQL is different from
>> > numeric or string data, I see nothing in the idea that indicates it is a
>> > value that is not part of the normal range of values.
>>
>> Perhaps you can think of Perl's undef as being part of the normal range
>> of values, too.
>>
> In principal I'd have no problem with that, if it weren't for the fact
> that Wall et al. described them as referring to variables that were
> not initialized.

You keep on and on repeating this but I've already pointed out to you
that it doesn't mean that. Did you actually try running or even
reading those scripts I gave? You need to spend a lot more time
reading and writing Perl code and a lot less time in creating mounds
of verbiage.

>> > I see nothing similar between the idea of NULL in SQL and either null or
>> > undefined in the other languages.
>>
>> That's odd, because the more you talk about SQL's NULL, the more it looks
>> like Perl's undefined value to me.
>>
> Until now, I had seen nothing written about perl that suggested that
> Wall et al.'s description of undefined meant anything other than a
> reference to variables that had not yet been initialized, and that is
> a very different concept from SQL's NULL.

Please don't say "not yet" again, I've already given you counter
examples for that.

> Why would you object to my leveraging what I know in other languages
> to learn Perl?

Since you've replied to my post, I assume you're addressing this
comment to me, so let me say that I don't remember objecting to
that.

Similar ThreadsPosted
Multiple Inheritance: mixed base class refs (hash, array) April 29, 2005, 2:29 am
FAQ 9.3: How can I get better error messages from a CGI program? December 5, 2004, 6:03 pm
FAQ 9.3: How can I get better error messages from a CGI program? December 29, 2004, 12:03 pm
FAQ 9.3 How can I get better error messages from a CGI program? March 25, 2005, 12:03 pm
FAQ 9.3 How can I get better error messages from a CGI program? June 4, 2005, 5:03 am
FAQ 9.3 How can I get better error messages from a CGI program? September 23, 2005, 4:03 pm
FAQ 9.3 How can I get better error messages from a CGI program? November 29, 2005, 5:03 am
FAQ 9.3 How can I get better error messages from a CGI program? September 17, 2006, 9:03 pm
FAQ 9.3 How can I get better error messages from a CGI program? March 21, 2007, 3:03 am
FAQ 9.3 How can I get better error messages from a CGI program? November 11, 2007, 9:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap