Ignore:
Timestamp:
04/27/17 00:47:33 (7 years ago)
Author:
nanardon
Message:

Use hash for loadCSV options to allow more parameters

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Utils.pm

    r1985 r1991  
    180180Parse CVS files and return an array for each parsed line. 
    181181 
    182 If defined call C<$callback> for parsed line. 
    183  
    184 C<$initcallback>, if defined, is called just after the first line. 
     182C<%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 
    185191 
    186192=cut 
    187193 
    188194sub loadCSV { 
    189     my ($fh, $cb, $initcb) = @_; 
     195    my ($fh, %opt) = @_; 
    190196 
    191197    my $csv = Text::CSV->new({ 
     
    201207    $csv->column_names($columns); 
    202208 
    203     if ($initcb) { 
    204         $initcb->($csv); 
     209    if ($opt{initcb}) { 
     210        $opt{initcb}->($csv); 
    205211    } 
    206212 
     
    209215    while ( my $row = $csv->getline_hr( $fh ) ) { 
    210216        $linecount++; 
    211         if ($cb) { 
    212             if (! $cb->($row, $linecount)) { 
     217        if ($opt{cb}) { 
     218            if (! $opt{cb}->($row, $linecount)) { 
    213219                return; 
    214220            } 
Note: See TracChangeset for help on using the changeset viewer.