in reply to Re^2: Arrays not being manipulated
in thread Arrays not being manipulated
Regardless, split(/\C/, $_) is still wrong. You want split(//, $_) instead. That will split "314" up into "3", "1", and "4" like you want.
Also, you don't need to declare them as global with our. Declare varaibles with my instead, when you first use them:
#!/usr/bin/perl -w #filename: myMutator.pl use strict; my $file = shift || "myFiles/pi.txt"; open(FILE, "< $file") or die "Couldn't open $file: $!"; my @numberMutation; while (<FILE>) { chomp; push(@numberMutation, split(//, $_)); } my @organism = (1,1,1,1,1,1,1,1,1); foreach my $currentMutation (@numberMutation) { my $i = 0; foreach my $currentGene (@organism) { if ($currentGene < $currentMutation) { $organism[$i] = $currentMutation; $i++; } } } foreach my $someGene (@organism) { print "$someGene\n"; } foreach my $thisMutate (@numberMutation) { print "$thisMutate\n"; }
I'm still not quite sure what you're trying to do, but if the file only contains a single line, you can avoid using a loop to read from it and just do this:
chomp(my $line = <FILE>); my @numberMutation = split(//, $line);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Arrays not being manipulated
by trammell (Priest) on Jan 01, 2005 at 19:37 UTC |