The problem with your code is that the
print statement is outside of the foreach loop (its outside of the curly braces which define the extent of the loop). To get it to print the second field on each line, this statement should be inside the loop so that it gets called for each line.
# type value value2
# 503 1093 4395
# load the data
@file = <FILE>;
# or use a while (defined(my $line = <FILE>)) { loop
for my $line (@file) { # for is the same as foreach
my @fields = split (/\s+/, $line); # @file was being reused
print "$fields[2]\n";
}
--
integral, resident of freenode's #perl