Revision e95294b5
Von Bernd Bleßmann vor fast 11 Jahren hinzugefügt
SL/Helper/Csv.pm | ||
---|---|---|
162 | 162 |
0, |
163 | 163 |
]) unless $h; |
164 | 164 |
|
165 |
push @{ $header }, $h; |
|
165 |
if ($self->is_multiplexed) { |
|
166 |
push @{ $header }, $h; |
|
167 |
} else { |
|
168 |
$header = $h; |
|
169 |
} |
|
166 | 170 |
} |
167 | 171 |
} |
168 | 172 |
|
... | ... | |
171 | 175 |
# data with a discouraged but valid byte order mark |
172 | 176 |
# if not removed, the first header field will not be recognized |
173 | 177 |
if ($header) { |
174 |
my $h = $header->[0]; |
|
178 |
my $h = ($self->is_multiplexed)? $header->[0] : $header; |
|
179 |
|
|
175 | 180 |
if ($h && $h->[0] && $self->encoding =~ /utf-?8/i) { |
176 | 181 |
$h->[0] =~ s/^\x{FEFF}//; |
177 | 182 |
} |
178 | 183 |
} |
179 | 184 |
|
180 | 185 |
# check, if all header fields are parsed well |
181 |
return unless $header && all { $_ } @$header; |
|
186 |
if ($self->is_multiplexed) { |
|
187 |
return unless $header && all { $_ } @$header; |
|
188 |
} else { |
|
189 |
return unless $header; |
|
190 |
} |
|
182 | 191 |
|
183 | 192 |
# Special case: human stupidity |
184 | 193 |
# people insist that case sensitivity doesn't exist and try to enter all |
... | ... | |
188 | 197 |
if ($self->case_insensitive_header) { |
189 | 198 |
die 'case_insensitive_header is only possible with profile' unless $self->profile; |
190 | 199 |
if ($header) { |
191 |
my $p_num = 0; |
|
192 |
foreach my $h (@{ $header }) { |
|
200 |
my $h_aref = ($self->is_multiplexed)? $header : [ $header ]; |
|
201 |
my $p_num = 0; |
|
202 |
foreach my $h (@{ $h_aref }) { |
|
193 | 203 |
my @names = ( |
194 | 204 |
keys %{ $self->profile->[$p_num]->{profile} || {} }, |
195 | 205 |
); |
... | ... | |
253 | 263 |
if ($self->is_multiplexed) { |
254 | 264 |
return $self->_row_header->{$row->[0]} |
255 | 265 |
} else { |
256 |
return $self->header->[0];
|
|
266 |
return $self->header; |
|
257 | 267 |
} |
258 | 268 |
} |
259 | 269 |
|
... | ... | |
322 | 332 |
sep_char => ',', # default ';' |
323 | 333 |
quote_char => '\'', # default '"' |
324 | 334 |
escape_char => '"', # default '"' |
325 |
header => [ [qw(id text sellprice word)] ], # see later
|
|
335 |
header => [ qw(id text sellprice word) ], # see later
|
|
326 | 336 |
profile => [ { profile => { sellprice => 'sellprice_as_number'}, |
327 | 337 |
class => 'SL::DB::Part' } ], |
328 | 338 |
); |
... | ... | |
427 | 437 |
|
428 | 438 |
=item C<header> \@HEADERS |
429 | 439 |
|
430 |
If given, it contains an ARRAYREF for each different class type (i.e. one |
|
431 |
ARRAYREF if the data is only of one class type). These ARRAYREFS are the header |
|
432 |
fields which are an array of columns. In this case the first lines are not used |
|
433 |
as a header. Empty header fields will be ignored in objects. |
|
440 |
If given, it contains an ARRAY of the header fields for not multiplexed data. |
|
441 |
Or an ARRAYREF for each different class type for multiplexed data. These |
|
442 |
ARRAYREFS are the header fields which are an array of columns. In this case |
|
443 |
the first lines are not used as a header. Empty header fields will be ignored |
|
444 |
in objects. |
|
434 | 445 |
|
435 | 446 |
If not given, headers are taken from the first n lines of data, where n is the |
436 | 447 |
number of different class types. |
... | ... | |
438 | 449 |
Examples: |
439 | 450 |
|
440 | 451 |
classic data of one type: |
441 |
[ [ 'name', 'street', 'zipcode', 'city' ] ]
|
|
452 |
[ 'name', 'street', 'zipcode', 'city' ]
|
|
442 | 453 |
|
443 | 454 |
multiplexed data with two different types |
444 | 455 |
[ [ 'ordernumber', 'customer', 'transdate' ], [ 'partnumber', 'qty', 'sellprice' ] ] |
Auch abrufbar als: Unified diff
Csv-Helper lässt header als einfaches Arrayref bei Nicht-Multiplex-Daten zu.