Thread CSV-Import mit Text::CSV (16 answers)
Opened by jan99 at 2015-08-31 13:13

jan99
 2015-08-31 15:57
#181960 #181960
User since
2008-09-18
439 Artikel
BenutzerIn
[default_avatar]
hi !

ist vorhanden ! Hier einmal komplett:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/perl
use strict;
use warnings;
use Text::CSV;
use Data::Dumper;

my $file='MenuGroup_bereinigt.csv';
my $s_delimiter = ";";

open(my $fh, '<', $file) or die("ERROR open $file ($!)\n");

my $csv = Text::CSV->new({binary => 1, sep_char => $s_delimiter});
#my $csv = Text::CSV->new ();

# first line
my $key_names=$csv->getline( $fh );

# Array of hashes
my @data;

# read File
while( my $row = $csv->getline( $fh ) )
{
  my $value={};
  $value->{$key_names->[$_]}=$row->[$_] for(0..$#$key_names);
  push(@data,$value);
}

$Data::Dumper::Useqq(1);
print Dumper(\@data);


Gruß Jan
perl-Greenhorn - Win7 64bit / strawberry (ehem. activeperl) - www.OpenStreetMap.de

View full thread CSV-Import mit Text::CSV