Unitialized variables

Discussion in 'Perl Misc' started by Brad, Sep 3, 2004.

  1. Brad

    Brad Guest

    Does anyone know a good test for an unitialzed variable? I tried
    "! defined $var", but that doesn't seem to work. I've also tried
    '$var eq ""' and that doesn't work either. Any suggestions would be
    greatly appreciated!
     
    Brad, Sep 3, 2004
    #1
    1. Advertising

  2. (Brad) wrote in
    news::

    > Does anyone know a good test for an unitialzed variable? I tried
    > "! defined $var", but that doesn't seem to work.


    What do you mean it does not work? What do you expect and what happens
    instead? Where is the code?

    C:\Home> cat d.pl
    my $var;
    print "\$var is not defined\n" if ! defined $var;
    print "\$var is not defined\n" unless defined $var;

    C:\Home> cat d.pl
    $var is not defined
    $var is not defined

    > I've also tried '$var eq ""' and that doesn't work either.


    my $var;
    print "\$var is not defined\n" if '$var eq ""';

    C:\Home> perl d.pl
    $var is not defined

    This last one underscores the importance of posting real code rather than
    BS.

    > Any suggestions would be greatly appreciated!


    Read the posting guidelines.

    Sinan.
     
    A. Sinan Unur, Sep 3, 2004
    #2
    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. Darrell Grainger

    Re: Unitialized Memory Read In sscanf()

    Darrell Grainger, Jun 24, 2003, in forum: C Programming
    Replies:
    1
    Views:
    837
    Alan Balmer
    Jun 24, 2003
  2. Eric Sosman

    Re: Unitialized Memory Read In sscanf()

    Eric Sosman, Jun 24, 2003, in forum: C Programming
    Replies:
    0
    Views:
    863
    Eric Sosman
    Jun 24, 2003
  3. Adam Monsen
    Replies:
    3
    Views:
    254
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Sep 9, 2005
  4. Greg

    Unitialized pointers?

    Greg, Oct 11, 2004, in forum: C Programming
    Replies:
    5
    Views:
    350
  5. Replies:
    2
    Views:
    317
Loading...

Share This Page