Perl Syntax
I'm using perl 5.8.4 on a 4.9 machine. I want to add code a perl script to check for value passed from command line. If it is null, I want to exit with an error message. First I tried this and got Use of uninitialized value in string eq at ./test.pl line 20. if ($ARGV[0] eq ) { print You must include the file name.; exit 1; } Next I tried this but get Use of uninitialized value in length at ./test.pl line 20. if (length ($ARGV[0]) = 0) { print You must include the file name.; exit 1; } I've searched the web and all examples that I've found indicate that I'm doing things correctly but obviously I'm not. What am I doing wrong? Thanks, Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, More! http://www.alchemistswarehouse.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl Syntax
I'm using perl 5.8.4 on a 4.9 machine. I want to add code a perl script to check for value passed from command line. If it is null, I want to exit with an error message. First I tried this and got Use of uninitialized value in string eq at ./test.pl line 20. if ($ARGV[0] eq ) { print You must include the file name.; exit 1; } Next I tried this but get Use of uninitialized value in length at ./test.pl line 20. if (length ($ARGV[0]) = 0) { print You must include the file name.; exit 1; } I've searched the web and all examples that I've found indicate that I'm doing things correctly but obviously I'm not. What am I doing wrong? I know this works: if ($ARGV[0] eq '') { print Debug Mode\n; } Cheers, Steve Thanks, Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, More! http://www.alchemistswarehouse.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED] ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl Syntax
On 6/30/2004 10:04 AM Steve Bertrand wrote: I'm using perl 5.8.4 on a 4.9 machine. I want to add code a perl script to check for value passed from command line. If it is null, I want to exit with an error message. First I tried this and got Use of uninitialized value in string eq at ./test.pl line 20. if ($ARGV[0] eq ) { print You must include the file name.; exit 1; } Next I tried this but get Use of uninitialized value in length at ./test.pl line 20. if (length ($ARGV[0]) = 0) { print You must include the file name.; exit 1; } I've searched the web and all examples that I've found indicate that I'm doing things correctly but obviously I'm not. What am I doing wrong? I know this works: if ($ARGV[0] eq '') { print Debug Mode\n; } Cheers, Steve Thanks for your reply. I tried your suggestion and it seems to work but I get this output: Use of uninitialized value in string eq at ./test.pl line 16. You must include the file name. I have use warnings; and use strict; in the script. I assume the error comes from the use warnings; but why does perl see eq as a string and not an operator? Or am I misinterpreting the message? Thanks, Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, More! http://www.alchemistswarehouse.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl Syntax
On Wed, Jun 30, 2004 at 10:17:45AM -0700, Drew Tomlinson wrote: On 6/30/2004 10:04 AM Steve Bertrand wrote: I know this works: if ($ARGV[0] eq '') { print Debug Mode\n; } Thanks for your reply. I tried your suggestion and it seems to work but I get this output: Use of uninitialized value in string eq at ./test.pl line 16. You must include the file name. Unless you supply at least one argument to the script, $ARGV[0] won't exist. There's a difference in perl between 'not defined' and an empty string (or zero for numerical values). Try: if ( @ARGV 1 ) { usage(); exit 1; } or unless ( defined $ARGV[0] ) { usage(); exit 1; } -- Dr Matthew J Seaman MA, D.Phil. 26 The Paddocks Savill Way PGP: http://www.infracaninophile.co.uk/pgpkey Marlow Tel: +44 1628 476614 Bucks., SL7 1TH UK pgpssHs1DxyBx.pgp Description: PGP signature
Re: Perl Syntax
I'm using perl 5.8.4 on a 4.9 machine. I want to add code a perl script to check for value passed from command line. If it is null, I want to exit with an error message. First I tried this and got Use of uninitialized value in string eq at ./test.pl line 20. if ($ARGV[0] eq ) { print You must include the file name.; exit 1; } Next I tried this but get Use of uninitialized value in length at ./test.pl line 20. if (length ($ARGV[0]) = 0) { print You must include the file name.; exit 1; } I've searched the web and all examples that I've found indicate that I'm doing things correctly but obviously I'm not. What am I doing wrong? I know this works: if ($ARGV[0] eq '') { print Debug Mode\n; } Cheers, Steve Thanks for your reply. I tried your suggestion and it seems to work but I get this output: Use of uninitialized value in string eq at ./test.pl line 16. You must include the file name. I have use warnings; and use strict; in the script. I assume the error comes from the use warnings; but why does perl see eq as a string and not an operator? Or am I misinterpreting the message? Thanks, Drew #!/usr/bin/perl -w if (!ARGV[0]) { print no arguements\n; } else { print found an arguement\n; } Josh Paetzel ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]
Re: Perl Syntax -- SOLVED
On 6/30/2004 10:34 AM Matthew Seaman wrote: On Wed, Jun 30, 2004 at 10:17:45AM -0700, Drew Tomlinson wrote: On 6/30/2004 10:04 AM Steve Bertrand wrote: I know this works: if ($ARGV[0] eq '') { print Debug Mode\n; } Thanks for your reply. I tried your suggestion and it seems to work but I get this output: Use of uninitialized value in string eq at ./test.pl line 16. You must include the file name. Unless you supply at least one argument to the script, $ARGV[0] won't exist. There's a difference in perl between 'not defined' and an empty string (or zero for numerical values). Try: if ( @ARGV 1 ) { usage(); exit 1; } or unless ( defined $ARGV[0] ) { usage(); exit 1; } Thank you very much for the explanation. Now I understand why I was getting the error message. I didn't quite understand how to use usage(); but replaced it with a print statement. It works perfectly! Thanks, Drew -- Visit The Alchemist's Warehouse Magic Tricks, DVDs, Videos, Books, More! http://www.alchemistswarehouse.com ___ [EMAIL PROTECTED] mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-questions To unsubscribe, send any mail to [EMAIL PROTECTED]