in reply to Arrays not being manipulated
Restating...
I want it to compare each element ($currentMutation) in the @numberMutation array to each element in the @organism array
and set the @organism[$i] = $currentMutation if (@organism[$i] < $currentMutation)
The @organism array is preset to all 1's.
Given this logic, ALL the elements of @organism will always be set to the highest value of $currentMutation.
use strict; ## Simplified for testing my @numberMutation = (); while (<DATA>) { chomp; @numberMutation = split(//,$_); } my @organism = (1,1,1,1,1,1,1,1,1); foreach (@numberMutation) { my $currentMutation = $_; my $i = 0; foreach (@organism) { if ($_ < $currentMutation) { $organism[$i] = $currentMutation; $i++; } } } print "ORG: @organism\n"; ## prints ORG: 9 9 9 9 9 9 9 9 9 print "MUT: @numberMutation\n"; __DATA__ 31415926535897932384626433832
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Arrays not being manipulated
by aristotle73 (Sexton) on Jan 01, 2005 at 20:29 UTC | |
by nedals (Deacon) on Jan 01, 2005 at 21:05 UTC | |
by aristotle73 (Sexton) on Jan 01, 2005 at 21:40 UTC |