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 Ted on April 24, 2008, 11:46 am
Please log in for more thread options
On Apr 24, 10:10=A0am, benkasminbull...@gmail.com (Ben Bullock) wrote:
> >> 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.
>
> Excuse me, this should say '$b is a "defined null string"' not "real".
>
OK. Where does this definition of a defined null string come from?
Wall et al. say nothing about it, either in their chapter two, where
they talk about types and other basic matters, or on page 155 where
they talk about undef.

> > 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.
>
Then why are you arguing in this thread.

The DBI is all about mapping SQL concepts to Perl concepts. Surely
this newsgroup is more logical as a place to discuss that than any
other. I'd assume that it was developed by perl programmers to meet
the need to be able to interact with databases.

And where exactly are you getting the idea that the empty string is a
defined null string. Wall et al. certainly make no reference to such
an idea whether where they talk about types in chapter 2 or where they
talk about undefined on page 155. It is, in fact, a bit of a
frustration that they reference the defined null string without
defining it. But I don't criticise them since there is no such thing
as a perfect product, and therefore any product can be improved.

> > But that is exactly what Wall et al. said about undefined. =A0I 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. =A0The 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=3D"" and $b=3Dundef are two totally different things.
>
Agreed. But the empty string is not a defined null, unless that
definition is provided somewhere in the Perl documentation. $b in
$b=3D"" is an empty string, neither null nor undefined. Apart from what
you have written here, I have seen nothing written about perl that
equates the empty string to a defined null.

Wall et al. say nothing about an empty string being conceived as being
the same thing as a defined null, either in their second chapter,
where they talk about types and other basic matters, or on page 155
where they talk about undef.

> >> > But ALL of these concepts are very different from the idea of NULL in=

> >> > SQL. =A0For example, The book, from Osborne, "SQL: The complete refer=
ence"
> >> > by James Groff and Paul Weinberg, described it as referring to data t=
hat
> >> > 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. =A0Where they wrong, or
> > merely misleading?
>
> Look at this kind of example:
>
> my @arr =3D (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) =3D @z;
>
> to ignore the value of $z[0].
>
This is new to me, and quite interesting. And it shows a behaviour
related to the behaviour of SQL NULLs.

> 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.
>
Read Abigail's posts. I found them priceless, and I thank her for
them, for I learned much from her comparison of SQL NULLs and Perl's
undef, especially what she said bout what happens on the Perl side.

> >> > While NULL in SQL is different from
> >> > numeric or string data, I see nothing in the idea that indicates it i=
s 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?
I repeated it because that is what they wrote, and there seems to be a
gulf between what they wrote and what you're writing. Yes, the
scripts show how Perl behaves in the xample context, but there is a
problem with your example because there is no substantiation of your
claim that the empty string is the same thing as a defined null
string. I do not have a problem with such a definition, but would
like to see it somewhere in the perl documents. Is it given there?
If so, where?

But the notion of a defined null string is really a side issue. It
has become appearent to me from what others have written in this
thread that Perl is doing implicitly, using undef, what I routinely do
explicitly in my C++ and Java code. It also does not address the core
problem that a variable that is not defined is not the same idea as
that represented in an SQL null.

> >> > 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 loo=
ks
> >> 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.
>
And as I pointed out, your examples that used $a and $b are
problematic, and thus don't settle the question. Further, your
counter examples don't address the fact I have not seen your use of
undefined as being equivalent in meaning to SQL's NULLs in other Perl
references. See Abigail's posts for a detailed explanation of the
problems with such an equivalence.

Yes, I did find the information you referred to on the DBI page, but
there was no explanation there for the rationale behind such a choice.

> > 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.

You did so implicitly by apparently complaining that I wrote too much
about these ideas as they are reflected in C++ and Java.
To quote what you said above: "But I'm not talking about C++ or Java
or SQL. I'm talking about Perl. This is a perl newsgroup." You seem
to be implying that mention of ideas expressed in C++ or Java or SQL
is forbidden in this newsgroup. If that is correct, it makes it
impossible to leverage what one knows of these other languages to
learn more about perl, and in particular that would make understanding
how and why the DBI maps SQL cncepts to Perl concepts.

If I misinterpreted what you meant by such comments, I apologize.

Cheers,

Ted

Posted by Peter J. Holzer on April 26, 2008, 6:20 am
Please log in for more thread options
> And where exactly are you getting the idea that the empty string is a
> defined null string.

Common usage. A "null string" is a string of length zero. It has nothing
to do with the concept of NULL in SQL. Using the term "null string"
instead of "empty string" in a thread about DBI is confusing, but since
it is quoted from a book which is not about DBI or SQL, but about Perl,
that's just the way it is. You have to learn that English words can mean
different things depending on context.

So, in Perl the "null string" ("") is defined and distinct from undef,
which is not a string (It is a scalar value, but it is neither a string,
nor a number, nor a reference - and any attempt to use it as such will
yield a warning).


>> > 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.

It also exactly describes a variable which has been initialized to
undef.

>> > The empty string is a valid string in all of the languages I use,
>> > and it means something quite different from a SQL null.

True, but irrelevant. Nobody ever claimed that they were the same (well,
Oracle does, but that's their problem).


>> 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.
>>
> Agreed. But the empty string is not a defined null,

Nobody said it was. "Null string" is a synonym for "empty string". In
Perl (defined("")) happens to be true.

        hp

Posted by Charlton Wilbur on April 28, 2008, 8:52 am
Please log in for more thread options


>> And where exactly are you getting the idea that the empty
>> string is a defined null string.

PJH> Common usage. A "null string" is a string of length zero.

Er, this is ambiguous to C programmers: there's a significant
difference between

char *foo = NULL;

and

char *foo = "";

and I would expect that reasonable C programmers would avoid using
"null string" because it's impossible to determine which of the two
the term refers to.

It's also ambiguous in SQL - NULL and '' are different values and can
mean different things.

And hey, it's ambiguous in Perl too - undef and '' are different
values, and can mean different things. The only difference is that
NULL isn't a keyword in Perl, and "null pointer" isn't a useful concept.

PJH> Using the term "null string" instead of "empty string" in a
PJH> thread about DBI is confusing, but since it is quoted from a
PJH> book which is not about DBI or SQL, but about Perl, that's
PJH> just the way it is. You have to learn that English words can
PJH> mean different things depending on context.

I'd side with Ted here, much as the tone of his argument has annoyed
me; there's a valuable distinction between null string and empty
string, even in Perl, and the text of the Camel book is unclear. The
term "null string" for what would more reasonably called an "empty
string" is a mistake. When the Camel is wrong, it should be
corrected, not defended as if it were Holy Writ.

Charlton


--
Charlton Wilbur
cwilbur@chromatico.net

Posted by Peter J. Holzer on April 28, 2008, 5:12 pm
Please log in for more thread options
>
>
> >> And where exactly are you getting the idea that the empty
> >> string is a defined null string.
>
> PJH> Common usage. A "null string" is a string of length zero.
>
> Er, this is ambiguous to C programmers:

No.

> there's a significant difference between
>
> char *foo = NULL;
>
> and
>
> char *foo = "";

Yes. Most importantly, the former doesn't contain a string.


> and I would expect that reasonable C programmers would avoid using
> "null string" because it's impossible to determine which of the two
> the term refers to.

Since the former doesn't contain a string, it can't be the one with the
null string. So it must be the second.


> It's also ambiguous in SQL - NULL and '' are different values and can
> mean different things.

Yes, when talking about SQL I would avoid talking about a null string.
But then, if I wanted to be exact, I would avoid talking about strings
at all, and talk about char or varchar values ...

Now, Java is a different matter. It does have a type "String" and null
is a valid value for that type. So in Java this really is ambiguous (and
in fact, when I googled for "null string", the only instances I found
where "null string" was not used synonymously with "empty string",
concerned Java).

> And hey, it's ambiguous in Perl too - undef and '' are different
> values, and can mean different things.

But only the latter is a string. undef is not a string and therefore
cannot be called the "null string". So it isn't ambiguous.


> The only difference is that NULL isn't a keyword in Perl, and "null
> pointer" isn't a useful concept.
>
> PJH> Using the term "null string" instead of "empty string" in a
> PJH> thread about DBI is confusing, but since it is quoted from a
> PJH> book which is not about DBI or SQL, but about Perl, that's
> PJH> just the way it is. You have to learn that English words can
> PJH> mean different things depending on context.
>
> I'd side with Ted here, much as the tone of his argument has annoyed
> me; there's a valuable distinction between null string and empty
> string, even in Perl, and the text of the Camel book is unclear.

There is a valuable distinction between undef and emtpy string. There is
no concept of a "null string" distinct from an empty string in Perl.

> The term "null string" for what would more reasonably called an "empty
> string" is a mistake. When the Camel is wrong, it should be
> corrected, not defended as if it were Holy Writ.

It isn't wrong. The use of the term is wide-spread and quite old. For
example, quickly grepping over the RFCs yields a hit in RFC 333 (written
in 1972!):

The symbolic identification strings are specified to be from 1 to 39
(an arbitrary maximum) ASCII characters terminated by a null (byte of
all zeroes). The characters will be 7-bit ASCII in 8-bit bytes with
the high order bit set to zero. A null string (first byte is null)
is used where no argument is required.

It may be that Ted and you are unfamiliar with this term. That doesn't
make it wrong (If every English term I'm unfamilar with was wrong, the
English would have a poor language, indeed). It may in some context be
ambiguous. I was going to criticize Ben (was it Ben?) for using the
phrase in this thread, but then I noticed that he hadn't brought it up,
but was merely discussing a quote from the Camel book. And I don't think
you can fault Wall et al for not anticipating that someone with a Java
and SQL background might misunderstand an term with an otherwise quite
specific meaning.

        hp


Posted by Charlton Wilbur on April 28, 2008, 5:58 pm
Please log in for more thread options

>> The term "null string" for what would more reasonably called an
>> "empty string" is a mistake. When the Camel is wrong, it
>> should be corrected, not defended as if it were Holy Writ.

PJH> It isn't wrong.

I didn't say it was *wrong*; I said it was a mistake, because of the
very ambiguity that you are alternately defending and insisting is not
present.

PJH> It may be that Ted and you are unfamiliar with this
PJH> term. That doesn't make it wrong (If every English term I'm
PJH> unfamilar with was wrong, the English would have a poor
PJH> language, indeed). It may in some context be ambiguous. I was
PJH> going to criticize Ben (was it Ben?) for using the phrase in
PJH> this thread, but then I noticed that he hadn't brought it up,
PJH> but was merely discussing a quote from the Camel book.

In other words, if Ben had written it originally, you would have
considered it a fault, but because it can be found in the Camel, it
becomes Holy Writ and thus to be defended as an article of faith.

PJH> And I don't think you can fault Wall et al for not
PJH> anticipating that someone with a Java and SQL background
PJH> might misunderstand an term with an otherwise quite specific
PJH> meaning.

Hardly; as I pointed out, it's also unclear in meaning for those of us
with C backgrounds as well, especially when the term "empty string"
conveys the same information without the prospect of ambiguity.

This has not appeared to be a rational argument for some time, and if
you prefer to defend inaccuracy and ambiguity with the delusion that
it's instantly clear to everyone except Java programmers, by all
means, carry on.

Charlton



--
Charlton Wilbur
cwilbur@chromatico.net

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