Thread Slice von Hashreferenz für Text::CSV (4 answers)
Opened by Gast at 2009-12-11 09:18

Gast Gast
 2009-12-11 09:18
#129184 #129184
Hallo!

Das funktioniert einigermaßen:

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
#!/usr/bin/perl
use 5.010;
use warnings;
use strict;
use Text::CSV;

my $file_in = 'addressbook.csv';
my $file_out = 'Test';
my $csv = Text::CSV->new( { binary => 1 } ) or die "Cannot use CSV: ".Text::CSV->error_diag();

open my $fh_in, '<:encoding(utf8)', $file_in or die $!;
open my $fh_out, '>:encoding(utf8)', $file_out or die $!;

my @felder = ( 'Nachname', 'Vorname', 'Mobiltelefon', 'Telefon (privat)', 'E-Mail-Adresse', 'Homepage', 'Jahrestag' );
$csv->print( $fh_out, \@felder );
say $fh_out '';


$csv->column_names( $csv->getline( $fh_in ) );

while ( my $hr = $csv->getline_hr( $fh_in ) ) {
    my @row = @{$hr}{@felder};
    $csv->print( $fh_out, \@row ); 
    say $fh_out '';
}


Wenn ich es so schreibe, geht es nicht mehr:
(Usage: Text::CSV_XS::print(self, io, fields) at ./text_CSV_adressbuck.pl line .., <$fh_in> line 2.)

Code (perl): (dl )
1
2
3
4
while ( my $hr = $csv->getline_hr( $fh_in ) ) {
    $csv->print( $fh_out, \@{$hr}{@felder} ); 
    say $fh_out '';
}


Woran liegt das?

View full thread Slice von Hashreferenz für Text::CSV