1
2
3
4
5
6
7
8
9
$input_file_name = "test_file.csv";
open (FILE,$input_file_name) or die "Can not open file $input_file_name!";
while ($line_query_input=<FILE>)
{
@query_input=split("\,",$line_query_input)) # Splits line into array
# #chomp($line_query_input); # Removes \n at every word
...
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/perl use strict; use warnings; use Text::CSV; # Ausgabe von Datenstrukturen use Data::Dumper; $input_file_name = "test_file.csv"; my $csv = Text::CSV->new ( { sep_char => ',', eol => $\ } ) open(my $fh,'<',$input_file_name) or die "Can not open file $input_file_name ($!)\n"; my @data; while ( my $row = $csv->getline( $fh ) ) { push(@data,$row); } print Dumper(\@data);
1 2 3 4 5 6 7 8 9 10 11 12 13
my @data_array; my %data_hash while (my $line = <$fh>) { chomp($line); # Variante 1: Anonyme Arrays my @values = split(/\s*,\s*/, $line); push @data_array, [@values]; # Variante 2: Hash mit Spalte 0 als key my ($key, @hvalues) = split(/\s*,\s*/, $line); $data_hash{$key} = [@hvalues]; }