Revision 7ec8b55e
Von Bernd Blessmann vor fast 11 Jahren hinzugefügt
SL/Helper/Csv.pm | ||
---|---|---|
7 | 7 |
use Carp; |
8 | 8 |
use IO::File; |
9 | 9 |
use Params::Validate qw(:all); |
10 |
use List::MoreUtils qw(all); |
|
10 |
use List::MoreUtils qw(all pairwise);
|
|
11 | 11 |
use Text::CSV_XS; |
12 | 12 |
use Rose::Object::MakeMethods::Generic scalar => [ qw( |
13 | 13 |
file encoding sep_char quote_char escape_char header profile |
14 | 14 |
numberformat dateformat ignore_unknown_columns strict_profile is_multiplexed |
15 |
_io _csv _objects _parsed _data _errors all_cvar_configs case_insensitive_header |
|
15 |
_row_header _io _csv _objects _parsed _data _errors all_cvar_configs case_insensitive_header
|
|
16 | 16 |
) ]; |
17 | 17 |
|
18 | 18 |
use SL::Helper::Csv::Dispatcher; |
... | ... | |
221 | 221 |
sub _header_by_row { |
222 | 222 |
my ($self, $row) = @_; |
223 | 223 |
|
224 |
my @header = @{ $self->header }; |
|
224 |
# initialize lookup hash if not already done |
|
225 |
if ($self->is_multiplexed && ! defined $self->_row_header ) { |
|
226 |
$self->_row_header({ pairwise { $a->{row_ident} => $b } @{ $self->profile }, @{ $self->header } }); |
|
227 |
} |
|
228 |
|
|
225 | 229 |
if ($self->is_multiplexed) { |
226 |
my $i = 0; |
|
227 |
foreach my $profile (@{ $self->profile }) { |
|
228 |
if ($row->[0] eq $profile->{row_ident}) { |
|
229 |
return $header[$i]; |
|
230 |
} |
|
231 |
$i++; |
|
232 |
} |
|
230 |
return $self->_row_header->{$row->[0]} |
|
233 | 231 |
} else { |
234 |
return $header[0];
|
|
232 |
return $self->header->[0];
|
|
235 | 233 |
} |
236 | 234 |
} |
237 | 235 |
|
Auch abrufbar als: Unified diff
Lookup-Hashes für Header, Klassen und Specs bei Multiplex-Daten benutzen.