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

Hello dbander,

Your solution unfortunately puts all data into the array. The OP will not be able to differentiate the data in order to create separate graphs.

Sample of code and output:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @histofeld = (); open my $input_file, '<', 'data.txt' or die "$!"; while (my $input_buffer = <$input_file>) { chomp $input_buffer; my @data = split(',',$input_buffer); push @histofeld, @data; } close $input_file; print Dumper \@histofeld; __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' ];

You should do something like that:

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @histofeld = (); open my $input_file, '<', 'data.txt' or die "$!"; while (my $input_buffer = <$input_file>) { chomp $input_buffer; my @data = split(',',$input_buffer); push @histofeld, [ @data ]; } close $input_file; print Dumper \@histofeld; __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 buchi2 (Acolyte) on Sep 01, 2017 at 08:38 UTC
    Hello!

    Thank you all very much.

    push @histofeld, [split ',', $tmp[$i]];
    This get it work. :)

    Regards, buchi