Click here to get back home

code help

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
code help jammer 02-27-2008
|--> Re: code help Jürgen Exner02-27-2008
---> Re: code help John W. Krahn02-27-2008
Posted by jammer on February 27, 2008, 9:54 pm
Please log in for more thread options
Why does this give a syntax error?


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


Posted by Jürgen Exner on February 27, 2008, 10:10 pm
Please log in for more thread options
>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

Posted by John W. Krahn on February 27, 2008, 10:31 pm
Please log in for more thread options
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

Posted by jammer on February 27, 2008, 11:11 pm
Please log in for more thread options
> jammer wrote:
> > Why does this give a syntax error?
>
> There is no syntax error there.
>
> > # not 2 arguments, print usage
> > if ($#ARGV !=3D 1) {
>
> That's a great way to confuse a newby. =A0Why does the comment say "2
> arguments" but you are comparing the variable to 1? =A0Try it like this:
>
> # not 2 arguments, print usage
> if ( @ARGV !=3D 2 ) {
>
> > =A0 =A0 =A0 =A0 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. :-(

Posted by Jim Gibson on February 28, 2008, 2:47 pm
Please log in for more thread options
In article

> > 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. :-(

That is why it is always best to post a *complete* program, not just a
code fragment. Compilers are not always very good about diagnosing the
source of errors and identifying the exact line where the error is
located.

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Similar ThreadsPosted
Code Quality and examples from the Perl source code April 11, 2006, 10:22 am
Separate Javascipt code from pure Perl code May 7, 2007, 3:58 am
how to convert the following ASP code to perl code May 6, 2007, 8:35 am
Can this code be better? August 24, 2004, 12:50 pm
help with code March 4, 2005, 7:29 am
Help with Code October 2, 2006, 12:23 pm
Please help with this code June 10, 2007, 3:59 pm
XS code February 7, 2008, 12:32 pm
The code below returns me nothing. July 30, 2004, 1:52 pm
criticize my code.. please? October 16, 2004, 10:57 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap