Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

NULL Variables

by dwalsh27 (Initiate)
on Feb 04, 2004 at 17:56 UTC ( #326537=perlquestion: print w/replies, xml ) Need Help??

dwalsh27 has asked for the wisdom of the Perl Monks concerning the following question:

I'm pretty new to pearl so pls excuse this stupid question. How do you set a variable to "null"?? When I leave it blank (such as ($a= )) I get errors. Thanks in advance..

Replies are listed 'Best First'.
Re: NULL Variables
by Limbic~Region (Chancellor) on Feb 04, 2004 at 18:16 UTC
    dwalsh27,
    Depending on what you mean - any one of the following might be what you want:
    my $var; # undefined $var = undef; # explicitly set to undefined undef $var; # explicitly set to undefined $var = ''; # defined, but empty - will test false $var = 0; # defined with a value - which will test false $var = \0; # defined with a value of null
    Cheers - L~R
      Thanks undef works. Isn't that the same as null??
        dwalsh27,
        No, undefined is not the same as being set to \0. That's why I said it depends on what you are trying to do with it. Unlike C, Perl strings are not null terminated. Maybe you are interested in knowing what is truth.

        Cheers - L~R

Re: NULL Variables
by valentin (Abbot) on Feb 04, 2004 at 18:01 UTC
    my $x; # this var is undef by default my $xx = undef; # set the var with a undefined value
Re: NULL Variables
by Art_XIV (Hermit) on Feb 04, 2004 at 18:32 UTC

    It sounds like dwalsh27 is trying to apply an idiom that he/she learned from another language, which is likely not appropriate for Perl.

    What is that you want to accomplish or that you're trying to figure out, dwalsh27?

    Hanlon's Razor - "Never attribute to malice that which can be adequately explained by stupidity"
Re: NULL Variables
by flyingmoose (Priest) on Feb 04, 2004 at 19:20 UTC

    People new to Perl should get a book. Seriously. Really, a forum can never measure up to a book for the basics. This item is relatively basic (and indeed introductory), thus is undoubtedly covered in the Llama or Camel books by O'Reilly -- both excellent references.

    If we answer this, and then answer "what is a semicolon used for", and so on, we end up writing a book ourselves. Please, find some suitable documentation and try to solve your problem on your own. When you gain some basic skill, and the knowledge of what the language is properly called (Perl), then come back to us.

    So, as nicely as possible ... RTFM.

      Yeah you dumbasses should just use the search function available in every book on the shelf.. /sarcasm Actually.. Sometimes it's nice to have answers which you know right at your finger tips. Just so you can verify that you are not going crazy. Also sometimes it's easier to search the net for something than it is searching a book for something that may or may not be in the index. Also, posts like this are easier for most people to read than cs books.
        I agree with the person above me. I was actually reading the Llama book, and was searching for a way to set a variable so that the defined () function would come back as false. Since i did not know about 'undef', it makes it kind of hard to search for it in a book. Just because it seems obvious to you doesn't mean everyone gets it. Is this forum about helping people with Perl or selling O'Reilly books? WTF? Thanks to the first poster who answered the question in less space than the others took to complain about it.
Re: NULL Variables
by Abigail-II (Bishop) on Feb 04, 2004 at 18:20 UTC
    You must be at the wrong website. This site is about the language Perl (which doesn't have "null"s nor "NULL"s). Pearl can be found at http://people.ku.edu/~nkinners/LangList/Langs/P/PEARL[1].htm, http://people.ku.edu/~nkinners/LangList/Langs/P/PEARL[2].htm, http://people.ku.edu/~nkinners/LangList/Langs/P/PEARL[3].htm, and http://people.ku.edu/~nkinners/LangList/Langs/P/PEARL[4].htm (4 different languages).

    (I'd normally make them links, but [ ] doesn't seem to like nested brackets, and I can't get perlmonks to recognize <a href = "foo">bah</a> as an HTML element.)

    Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://326537]
Approved by b10m
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2020-07-09 22:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?