Changeset 1991
- Timestamp:
- 04/27/17 00:47:33 (7 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LATMOS-Accounts-Web/lib/LATMOS/Accounts/Web/Controller/Tools/CSV.pm
r1990 r1991 42 42 loadCSV( 43 43 $upload->fh, 44 sub {44 cb => sub { 45 45 my ($res, $count) = @_; 46 46 … … 75 75 return 1; 76 76 }, 77 sub {77 initcb => sub { 78 78 my ($csv) = @_; 79 79 @{ $c->stash->{attrs} } = $csv->column_names; -
trunk/LATMOS-Accounts/bin/la-load-csv
r1988 r1991 68 68 loadCSV( 69 69 $fh, 70 sub {70 cb => sub { 71 71 my ($res, $linecount) = @_; 72 72 … … 82 82 $ochelper->Automate($info) or 83 83 die "Cannot create object line $linecount (not enough information ?)\n"; 84 } 84 }, 85 85 ); 86 86 -
trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm
r1985 r1991 180 180 Parse CVS files and return an array for each parsed line. 181 181 182 If defined call C<$callback> for parsed line. 183 184 C<$initcallback>, if defined, is called just after the first line. 182 C<%options> may contains 183 184 =over 4 185 186 =item C<initcb> An function call after parsing first line 187 188 =item C<cb> A function call for each line 189 190 =back 185 191 186 192 =cut 187 193 188 194 sub loadCSV { 189 my ($fh, $cb, $initcb) = @_;195 my ($fh, %opt) = @_; 190 196 191 197 my $csv = Text::CSV->new({ … … 201 207 $csv->column_names($columns); 202 208 203 if ($ initcb) {204 $ initcb->($csv);209 if ($opt{initcb}) { 210 $opt{initcb}->($csv); 205 211 } 206 212 … … 209 215 while ( my $row = $csv->getline_hr( $fh ) ) { 210 216 $linecount++; 211 if ($ cb) {212 if (! $ cb->($row, $linecount)) {217 if ($opt{cb}) { 218 if (! $opt{cb}->($row, $linecount)) { 213 219 return; 214 220 }
Note: See TracChangeset
for help on using the changeset viewer.