raj8 has asked for the wisdom of the Perl Monks concerning the following question: (arrays)

Hello Perl Monks, I am have been attempting to unpack columns and increment the output, however, the increment operator starts at 1. Here is an example output:
drive 0 dirve 1 drive 2 drive 3 I am using this: open(LIST,"list -l|"); while(<LIST>) { ($drive) = unpack '@0 A3',$_; if(/Drive/) { $count++; } system("list -delete -dr -index ${count}"); }; However, when it gets to 3 it says can't delete 4 because the $i++ started at 1 instead of 0.
Any suggestions would help. thanks-- raj8

Originally posted as a Categorized Question.

Replies are listed 'Best First'.
Re: How can I start incrementing an index at 0?
by Adam (Vicar) on Sep 02, 2000 at 05:33 UTC
    First of all, the quick answer: declare $count = -1; somewhere earlier.

    Next the long answer. Your code is not good for a variety of reasons, most of which you learn from practice and experience, which if you hang out here you will gain quickly. Try this:

    use strict; # always. my $drive; my $count = -1; open( LIST, "list -l|" ) or die $!; while(<LIST>) { ($drive) = unpack '@0 A3',$_; ++$count if m/Drive/; system("list -delete -dr -index ${count}"); }
    This code can still made better, but that should get you off to a good start.