Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > code help

Reply
Thread Tools

code help

 
 
jammer
Guest
Posts: n/a
 
      02-28-2008
Why does this give a syntax error?


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

 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      02-28-2008
jammer <(E-Mail Removed)> wrote:
>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
 
Reply With Quote
 
 
 
 
John W. Krahn
Guest
Posts: n/a
 
      02-28-2008
jammer wrote:
> 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
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
 
Reply With Quote
 
jammer
Guest
Posts: n/a
 
      02-28-2008
On Feb 27, 10:31*pm, "John W. Krahn" <(E-Mail Removed)> wrote:
> jammer wrote:
> > 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM
Re: help with repeater, how to code it in code-behind page Phil Winstanley [Microsoft MVP ASP.NET] ASP .Net 2 06-25-2004 03:38 AM
help with repeater, how to code it in code-behind page Tee ASP .Net 1 06-24-2004 12:42 PM
Fire Code behind code AND Javascript code associated to a Button Click Event =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= ASP .Net 4 02-11-2004 07:31 AM
<code>linklist<Item,8> ItemList;</code> help! tone HTML 4 11-19-2003 02:57 PM



Advertisments