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.


In reply to Re: Why do i get an extra (duplicate) array element?- by graff
in thread Why do i get an extra (duplicate) array element?- by rickman1

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.