http://qs321.pair.com?node_id=128198


in reply to Invalid use of constant pragma?

ARGV elements are undef, not a null string, when not supplied. Try the following to see...
use Data::Dumper; # Because of my C++ background use constant PROJECT => $ARGV[0]; use constant ARCHIVE => $ARGV[1]; # debuggging print "PROJECT value = " . PROJECT . "\n"; print "ARCHIVE value = " . Dumper(ARCHIVE) . "\n"; if( ARCHIVE eq "") { warn( "No archive file was supplied.\n"); exit 1201; }

Replies are listed 'Best First'.
Re: Re: Invalid use of constant pragma?
by Fastolfe (Vicar) on Nov 29, 2001 at 09:22 UTC
    The fact that $ARGV[1] (thus ARCHIVE) is undef and not an empty string isn't really relevent. He's doing a test for string equality via eq, and undef stringifies to an empty string, so the test should succeed.
    $ perl -e 'print "OK\n" if undef eq ""' OK
      D'Oh! You are, of course, correct :/

      I'll just pass along tye's CB suggestion that perhaps use strict; would be in order, to verify no typos exist in the actual code.

      Mike

      use strict; - don't leave home without it

Re: Re: Invalid use of constant pragma?
by dhable (Monk) on Nov 29, 2001 at 02:28 UTC
    I did try the Data::Dumper package and I got the following output:
    ARCHIVE value = $VAR1 = '';
    Does this mean that the variable is set? I thought that's what I read about Data::Dumper.
      Interesting. When I run the program as in my previous node it displays ARCHIVE value = $VAR1 = undef; This is with Perl 5.6.0, ActiveState build#623.
        ActiveState v5.6.1 build 629