Here's the code. When I run it, the array prints fine in the while loop but I get the last person in every array element in the for loop.
Thanks in advance.
File:
Jerry,12
Lon,11
Jon,10
Mike,9
Perl code (on linux)
[code=perl]
#!/usr/bin/perl
open (FILE, "try.txt");
$x = 0;
while(<FILE>) {
chomp;
($STUDENT,$GR)= split(/,/);
$hold[$x,1] = $STUDENT;
$hold[$x,2] = $GR;
print "$x: $hold[$x,1],$hold[$x,2]\n";
$x = $x+1;
}
close(FILE);
for ($i = 0; $i < 4; $i++){
print "$i -- NAME--$hold[$i,1],GRADE--$hold[$i,2]\n";
}
;
[/code]
Thanks in advance.
File:
Jerry,12
Lon,11
Jon,10
Mike,9
Perl code (on linux)
[code=perl]
#!/usr/bin/perl
open (FILE, "try.txt");
$x = 0;
while(<FILE>) {
chomp;
($STUDENT,$GR)= split(/,/);
$hold[$x,1] = $STUDENT;
$hold[$x,2] = $GR;
print "$x: $hold[$x,1],$hold[$x,2]\n";
$x = $x+1;
}
close(FILE);
for ($i = 0; $i < 4; $i++){
print "$i -- NAME--$hold[$i,1],GRADE--$hold[$i,2]\n";
}
;
[/code]
Comment