code help

J

jammer

Why does this give a syntax error?


# not 2 arguments, print usage
if ($#ARGV != 1) {
print "\nusage: " . $ARGV[0] . "\[backupDir\] \
[backupConfigFile\]\n";
}
 
J

Jürgen Exner

jammer said:
Why does this give a syntax error?


# not 2 arguments, print usage
if ($#ARGV != 1) {
print "\nusage: " . $ARGV[0] . "\[backupDir\] \
[backupConfigFile\]\n";
}

It doesn't for me:

C:\tmp>type t.pl
# not 2 arguments, print usage
if ($#ARGV != 1) {
print "\nusage: " . $ARGV[0] . "\[backupDir\] \
[backupConfigFile\]\n";
}

C:\tmp>perl -c t.pl
t.pl syntax OK

jue
 
J

John W. Krahn

jammer said:
Why does this give a syntax error?

There is no syntax error there.
# not 2 arguments, print usage
if ($#ARGV != 1) {

That's a great way to confuse a newby. Why does the comment say "2
arguments" but you are comparing the variable to 1? Try it like this:

# not 2 arguments, print usage
if ( @ARGV != 2 ) {
print "\nusage: " . $ARGV[0] . "\[backupDir\] \

Unlike C, Python, etc. the first argument of @ARGV is *not* the program
name, you want the $0 variable instead.
[backupConfigFile\]\n";
}


John
 
J

jammer

jammer said:
Why does this give a syntax error?

There is no syntax error there.
# not 2 arguments, print usage
if ($#ARGV != 1) {

That's a great way to confuse a newby.  Why does the comment say "2
arguments" but you are comparing the variable to 1?  Try it like this:

# not 2 arguments, print usage
if ( @ARGV != 2 ) {
        print "\nusage: " . $ARGV[0] . "\[backupDir\] \

Unlike C, Python, etc. the first argument of @ARGV is *not* the program
name, you want the $0 variable instead.

I had a missing semi-colon and the error pointed to that block. :-(
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top