perl null value ?

A

Alexandre Jaquet

Hi how can make a test if ($var ne null) { print "not null"; } when I'm
doing that I got the following error msg :

bareword "NULL" not allowed while "strict subs" in use at

thx in advance
 
J

Jürgen Exner

Alexandre said:
Hi how can make a test if ($var ne null) { print "not null"; } when
I'm doing that I got the following error msg :

bareword "NULL" not allowed while "strict subs" in use at

If you want to compare the value of $var against a string then you have to
tell Perl that you are using a string and not e.g. function call:

if ($var ne 'null') { print "not null"; }

Note: this still may not do what you want it to do. Somehow this null looks
suspiciously like you want to compare against the empty string, a \000, or
the numerial value 0.
But because you didn't tell us what you actually want to do there is no for
us to say how to do it.

jue
 
P

Paul Lalli

Alexandre Jaquet said:
Hi how can make a test if ($var ne null) { print "not null"; } when I'm
doing that I got the following error msg :

bareword "NULL" not allowed while "strict subs" in use at

What, exactly, do you mean by 'null' in this case? Are you talking
about a variable which has not yet been defined?

if (defined ($var) ) { print "not undefined\n"; }

Are you talking about a variable that has a false value?

if ($var) { print "not false\n"; }

Are you talking about a variable whose value is a string containing the
null character?

if ($var ne "\000") { print "not the null character\n"; }

Or do you mean something else entirely? "null" is not a special or
defined word in Perl syntax. You need to tell us what you're actually
trying to do.

Paul Lalli
 
J

jeremiah johnson

The Perl "null" values are:

1) '' The empty string
2) '0' Zero in single quotes
3) undef very similar to the NULL in other languages
4) .. can't remember the fourth. sorry, tad.

but since Perl will return what it thinks you want, you really don't
have to worry about it.

try this:

if ($var) { print "not null\n"; }

if $var contains anything other than one of the four false values
mentioned above, the condition will evaluate as true, and execution will
proceed into the curly braces.

jeremiah();
 
P

Paul Lalli

Please do not top quote. Thank you.
The Perl "null" values are:

There is no such thing as 'null'. What you have listed are the values
that evaluate to false in a boolean context.
1) '' The empty string
2) '0' Zero in single quotes

You mean "string containing only the character '0'". The single quotes
are irrelevant, as there is no difference between single and double
quotes (unless a variable or escape sequence is included in the string,
which they are not in this case)
3) undef very similar to the NULL in other languages
4) .. can't remember the fourth. sorry, tad.

The numeric value 0. Either a numeric literal typed into your code (0,
0.0, 0x00, etc), or a the result of a mathematical computation which is
equal to 0.

Paul Lalli
 
T

Tad McClellan

[ Please do not top-post. Text rarranged into chronological order. ]


The Perl "null" values are:


Perl does not have a "null".

Only the OP knows what "null" is, we don't have enough
information to answer the question...



The Perl _false_ values are:
1) '' The empty string
2) '0' Zero in single quotes


The "in single quotes" doesn't belong there, that is syntax (code)
while here we have been speaking of values (data).


2) '0' The 1-character string where the 1 character is the zero digit

is the best I've come up with.

3) undef very similar to the NULL in other languages
4) .. can't remember the fourth. sorry, tad.


4) 0 Numerically zero


:)
 
A

A. Sinan Unur

The Perl "null" values are:

1) '' The empty string
2) '0' Zero in single quotes

What is the difference between 'zero in single quotes' and 'zero in
double quotes'? ITYM a string consisting only of the 0 character.
3) undef very similar to the NULL in other languages
4) .. can't remember the fourth. sorry, tad.

You seem to be confused. I have no idea what Perl "null" values are, but
1, 2, and 3 are not equivalent.
but since Perl will return what it thinks you want, you really don't
have to worry about it.

try this:

if ($var) { print "not null\n"; }

There is a difference between false and undef.

use strict;
use warnings;

my @false = (0, '', '0', undef);

for my $f (@false) {
print "[$f] : True!\n" if defined $f;
}

__END__

Sinan
 
A

A. Sinan Unur

take your elitist attitude and shove it. i will not be reposting.

Thank you for allowing the average IQ level to increase by leaving.

*PLONK* anyway.

Sinan
 
T

Tad McClellan

jeremiah johnson said:
take your elitist attitude and shove it.


That is pretty anti-social of you.

Why not post the way everybody else likes instead of the way you like?

Everybody else is supposed to conform to _you_ rather than
the other way around?

That is an unreasonable expectation, you are likely to be disappointed.


I recommended that you read the Posting Guidelines before posting to avoid
becoming widely killfiled.

That didn't work in this case. :-(



*plonk*
 
T

Tad McClellan

jeremiah johnson said:
take your elitist attitude and shove it.


Asking the many to conform to the few is elitist.

_You_ are the one being elitist here!

i will not be reposting.


Thank you for doing your part to make this a better newsgroup.


( I am shocked at appalled at your followup. You seemed
well adjusted in person.)
 
A

Arndt Jonasson

Alexandre Jaquet said:
Hi how can make a test if ($var ne null) { print "not null"; } when
I'm doing that I got the following error msg :

bareword "NULL" not allowed while "strict subs" in use at

You can't have gotten a message about "NULL" when your code contains
"null". Perl is case sensitive.

As others have said, Perl doesn't define the word "null" to mean
anything in particular, but note that the documentation often uses
"null" as an adjective to mean "empty", as in "null string" or "null
list".
 
J

Jazeker

Alexandre said:
Hi how can make a test if ($var ne null) { print "not null"; } when I'm
doing that I got the following error msg :

bareword "NULL" not allowed while "strict subs" in use at

thx in advance

in Perl, the undefined value 'undef' approaches the classical null the
best. So check with if (defined($something))
 
T

Tad McClellan

Alexandre Jaquet said:
Subject: Re: perl null value ?


Perl does not have a null value, so you will need to tell us
what you mean when you say null value...

Hi how can make a test if ($var ne null) { print "not null"; } when I'm
doing that I got the following error msg :

bareword "NULL" not allowed while "strict subs" in use at


"bareword" means unquoted.

You should put quotes around your strings:

if ($var ne 'null') { print "not null"; }
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top