in reply to Store the outcome of a foreach loop in an array

The code you've showed appears to work fine for me - maybe $lines doesn't contain what you think it does? In this WebPerl live demo (requires a modern browser), I've shown how to use Data::Dumper to inspect data structures.

You should probably also heed the warning that Perl gives you: "Scalar value @val[2] better written as $val[2] "- the former is a "slice" and is not the best way to access a single array element.

Update: Code from WebPerl reproduced here:

use warnings; use strict; use Data::Dumper; $Data::Dumper::Useqq=1; my $lines = ["A,B,C","D,E,F","G,H,I"]; print Dumper($lines); my @store; foreach my $line (@$lines) { my @val = split(/\,/,$line); print Dumper(\@val); push (@store,@val[2]); } print Dumper(\@store);