[comp.lang.perl] Bug?

marc@athena.mit.edu (10/01/90)

The following perl program:

    #!/mit/watchmaker/@sys/perl
    $" = ","; print "$[-$#ARGV:$ARGV[0]:@ARGV\n";

    for ($i=$[; $i<=$#ARGV; $arg = $ARGV[$i++]) {
	    print "\$i=$i; \$arg=$arg\n";
    }

When executed as follows, seems to yield incorrect output:

    <81> steve-dallas:~> perl/ftest.pl a b c
    0-2:a:a,b,c
    $i=0; $arg=
    $i=1; $arg=a
    $i=2; $arg=b

By the time that $i gets printed, it should have been incremented by 1
already, so I should see 

    0-2:a:a,b,c
    $i=1; $arg=a
    $i=2; $arg=b
    $i=3; $arg=c

as output (I think).  Is there anything painfully obvious that I'm
doing wrong?  btw, I'm using a for loop instead of forach for a
specific reason, so that isn't an option.

		Marc

marc@athena.mit.edu (10/01/90)

|> You're doing something obviously wrong.  Let's rewrite the for
|> loop as a while loop...

Right.  So it's 1am :-)  Thanks.

		Marc