in reply to Re: Re: Initialize array
in thread Initialize array
First off, the indices of an array go from 0 to $#lines. So, when you do $number1 <= 0 as a boundary condition, you're already cutting off one of your useable indices.
The second thing is that you're comparing the number they give you (from 1 .. N) to a range from (0 .. N-1). I would do a $number1--; right after the chomp.
The third thing is that you're using | (the bit-wise OR) when I think you mean to be using || (the logical OR).
A few style notes:
open IN, "<$filename" or die "Cannot open $filename\n"; my @lines = <IN>; close IN or die "Cannot close $filename\n"; @lines = grep !/\s*[a-qs-zA-Z]/, @lines;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re4: Initialize array
by Hofmator (Curate) on Jul 04, 2001 at 18:52 UTC |