in reply to Re: How to get data to an array?
in thread How to get data to an array?

Hello flightdm,

You do not need to open the file handle and pass it to the diamond operator for reading. You can do it all in one, ref. I/O Operators. Read also eof for multiple files.

Sample of code with output:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @data; while (<>){ chomp; push @data, [split /,/]; } print Dumper \@data; __END__ ~/PerlMonks$ perl test.pl data.txt $VAR1 = [ [ '1', '5', '7', '8', '9', '10', '11', '3', '3', '5', '5', '5', '7', '2', '2' ], [ '2', '6', '7', '8', '9', '15', '17', '3', '4', '5', '6', '5', '7', '2', '3' ] ];

Hope this helps, BR.

Seeking for Perl wisdom...on the process of learning...not there...yet!

Replies are listed 'Best First'.
Re^3: How to get data to an array?
by flightdm (Acolyte) on Sep 13, 2017 at 04:27 UTC
    Hi -

    Thanks, but I'm quite familiar with the DATA filehandle, STDIN, and other methods of getting the data in. I'm not sure why you're bringing it up, since the scenario I stated -

    If you're trying to read a file that is composed of lines with comma-separated values

    - explicitly specifies an external file, as does the OP's request... and your addendum has no relation to the solution that was asked for (that is, getting data into an array.)

    Perhaps it'll add to someone's education, though.