code help

Discussion in 'Perl Misc' started by jammer, Feb 28, 2008.

  1. jammer

    jammer Guest

    Why does this give a syntax error?


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

  2. jammer <> 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
     
    Jürgen Exner, Feb 28, 2008
    #2
    1. Advertising

  3. 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
     
    John W. Krahn, Feb 28, 2008
    #3
  4. jammer

    jammer Guest

    On Feb 27, 10:31 pm, "John W. Krahn" <> 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. :-(
     
    jammer, Feb 28, 2008
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=

    Fire Code behind code AND Javascript code associated to a Button Click Event

    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=, Feb 10, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    21,293
    =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?=
    Feb 11, 2004
  2. Tee
    Replies:
    1
    Views:
    4,149
    Raterus
    Jun 24, 2004
  3. Phil Winstanley [Microsoft MVP ASP.NET]

    Re: help with repeater, how to code it in code-behind page

    Phil Winstanley [Microsoft MVP ASP.NET], Jun 24, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    478
    Ireney Berezniak
    Jun 25, 2004
  4. keithb
    Replies:
    1
    Views:
    939
    Bruce Barker
    Mar 29, 2006
  5. tone
    Replies:
    4
    Views:
    461
    Hywel Jenkins
    Nov 19, 2003
Loading...

Share This Page