in reply to How to get data to an array?
isn't particularly useful since you're assigning a scalar list reference to an array (meaning that you'll always end up with a single-element array.) Something like this would make more sense:my @data = [1,5,7,8,9,10,11,3,3,5,5,5,7,2,2];
I'm going to make some assumptions here about what you're trying to do; please feel free to correct any false ones. If you're trying to read a file that is composed of lines with comma-separated values, and where each line should be read in as a list reference of the above type, then something like this should be useful:my $data = [1,5,7,8,9,10,11,3,3,5,5,5,7,2,2];
Each of the elements of @data will be a reference to a list containing the values on each line.use strict; open my $fh, '<', 'file' or die "file: $!\n"; my @data; while (<$fh>){ chomp; push @data, [split /,/]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to get data to an array?
by thanos1983 (Parson) on Sep 01, 2017 at 00:15 UTC | |
by flightdm (Acolyte) on Sep 13, 2017 at 04:27 UTC |