perl null value ?

Discussion in 'Perl Misc' started by Alexandre Jaquet, Feb 22, 2005.

  1. 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
     
    Alexandre Jaquet, Feb 22, 2005
    #1
    1. Advertising

  2. Alexandre Jaquet wrote:
    > 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
     
    Jürgen Exner, Feb 22, 2005
    #2
    1. Advertising

  3. Alexandre Jaquet

    Paul Lalli Guest

    "Alexandre Jaquet" <> wrote in message
    news:cvfjlv$ggc$...
    > 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
     
    Paul Lalli, Feb 22, 2005
    #3
  4. 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();



    Alexandre Jaquet wrote:
    > 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
     
    jeremiah johnson, Feb 22, 2005
    #4
  5. Alexandre Jaquet

    Paul Lalli Guest

    "jeremiah johnson" <> wrote in message
    news:VAJSd.16835$g44.4652@attbi_s54...

    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
     
    Paul Lalli, Feb 22, 2005
    #5
  6. [ Please do not top-post. Text rarranged into chronological order. ]


    jeremiah johnson <> wrote:
    > Alexandre Jaquet wrote:
    >> Hi how can make a test if ($var ne null) { print "not null"; } when I'm


    > 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


    :)


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 22, 2005
    #6
  7. take your elitist attitude and shove it. i will not be reposting.


    Paul Lalli wrote:
    > "jeremiah johnson" <> wrote in message
    > news:VAJSd.16835$g44.4652@attbi_s54...
    >
    > Please do not top quote. Thank you.
     
    jeremiah johnson, Feb 22, 2005
    #7
  8. jeremiah johnson <> wrote in news:VAJSd.16835$g44.4652
    @attbi_s54:

    > 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. Sinan Unur, Feb 22, 2005
    #8
  9. jeremiah johnson <> wrote in news:RkKSd.42339$4q6.25847
    @attbi_s01:

    > Paul Lalli wrote:
    >> "jeremiah johnson" <> wrote in message
    >> news:VAJSd.16835$g44.4652@attbi_s54...
    >>
    >> Please do not top quote. Thank you.


    > 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
     
    A. Sinan Unur, Feb 22, 2005
    #9
  10. jeremiah johnson <> wrote:

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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 22, 2005
    #10
  11. jeremiah johnson <> wrote:
    > Paul Lalli wrote:
    >> "jeremiah johnson" <> wrote in message
    >> news:VAJSd.16835$g44.4652@attbi_s54...
    >>
    >> Please do not top quote. Thank you.



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


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Feb 22, 2005
    #11
  12. Alexandre Jaquet <> writes:
    > 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".
     
    Arndt Jonasson, Feb 23, 2005
    #12
  13. Alexandre Jaquet

    Jazeker Guest

    Alexandre Jaquet wrote:
    > 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))

    --
    print <<EOF;
    Just a noobish Perl hacker
    EOF
     
    Jazeker, Mar 4, 2005
    #13
  14. Alexandre Jaquet <> wrote:

    > 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"; }


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 5, 2005
    #14
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kivak Wolf
    Replies:
    2
    Views:
    10,095
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,234
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    5
    Views:
    26,919
    Mike Schilling
    Mar 29, 2006
  4. moonhk
    Replies:
    5
    Views:
    555
    moonhk
    Oct 11, 2006
  5. Col
    Replies:
    1
    Views:
    636
    peter koch
    Apr 21, 2006
Loading...

Share This Page