Based on the last thing you said:
My goal is to somehow stuff all neg values within one array and pos values within another...
I would think you want something like this:
my @pos_array;
my @neg_array;
while ( my $row = <IN> ) {
if ( /(-\d[.\d]+)/ ) {
push @neg_array, $1;
}
elsif ( /(\d[.\d]+)/ ) {
push @pos_array $1;
}
}
# now do stuff with those two arrays...
(There are better regex patterns for matching numeric strings, but the above works in the vast majority of cases.)
As for why your script is doing what it does, well, it's hard to say without seeing the actual input data. How about you post your code with data, like this, so we can see what's happening:
#!/usr/bin/perl
use strict;
use warnings;
while ( my $row = <DATA>) {
print $row;
}
__DATA__
10.00
10.00
-30.00
(Of course, your code and/or data will probably look different -- this is just a demonstration of the idea.)
One last point: substr() returns a scalar, not an array; your code is creating an array with a single element on each loop iteration, and that single element is a string of (up to) 17 characters long. The code doesn't make much sense, actually. |