rickman1 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to populate an array with dollar amounts from a text file via a while loop. I read them in line by line using substr. When I print out the array contents the last amount is displayed twice:
my $row; my $val; while ($row = <IN>) { $val = substr($row,0,1); @tranAmount = substr($row,68,17); foreach (@tranAmount) { print "$_\n"; } }
Output:
10.000
10.000
10.000
-30.000
-30.000 <--why is this happening? there are only 4 values within text file(10, 10, 10 and -30)
My goal is to somehow stuff all neg values within one array and pos values within another, so i can then do math with them, but i am running into this from the get-go, one hurdle at a time i guess. Thank you.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Why do i get an extra (duplicate) array element?-
by AnomalousMonk (Archbishop) on Jun 23, 2016 at 18:34 UTC | |
by rickman1 (Novice) on Jun 23, 2016 at 19:44 UTC | |
by AnomalousMonk (Archbishop) on Jun 23, 2016 at 21:40 UTC | |
|
Re: Why do i get an extra (duplicate) array element?-
by graff (Chancellor) on Jun 23, 2016 at 18:41 UTC | |
by TomDLux (Vicar) on Jun 23, 2016 at 19:18 UTC | |
|
Re: Why do i get an extra (duplicate) array element?-
by BillKSmith (Monsignor) on Jun 23, 2016 at 19:35 UTC | |
|
Re: Why do i get an extra (duplicate) array element?-
by perlfan (Parson) on Jun 23, 2016 at 18:38 UTC | |
by rickman1 (Novice) on Jun 23, 2016 at 20:14 UTC | |
by Marshall (Canon) on Jun 23, 2016 at 23:17 UTC |