I like the version that Khen1950x, but as you suggest in your last question, I'd also pass $hl to the callback function so you don't have to rely on the global. Here's his version with the (untested) change:
#!/usr/bin/perl use strict; use warnings; sub cell_walk { my $self = shift @_; my ( $sheet_name, $x, $y, $callback, $callback_data ) = @_; my $Sheet = $$self{'book_handle'}->Worksheets($sheet_name); foreach $row( $row = $$x[0] ; $row <= $$y[0] ; ++$row ) { for ( my $col = $$x[1] ; $col <= $$y[1] ; ++$col ) { &$callback( $Sheet->Cells( $row, $col ), $callback_data ); } } } sub callback { # $_[0] = excel cell reference, $_[1] = XYZ object reference return if not defined $_[0]{'Value'}; if ( $_[0]{'Value'} =~ /^~~~/ ) { my (@a) = split( /__/, substr( $_[0]{'Value'}, 3 ), 0 ); if ( scalar @a == 3 ) { $_[0]{'Value'} = $_[1]->get_single_LP( 'ADAS_VAL_RAW', @a +); } if ( scalar @a == 4 ) { $_[0]{'Value'} = $_[1]->accu_LP( 'ADAS_VAL_NORM', @a ); } } }
...roboticus
When your only tool is a hammer, all problems look like your thumb.
In reply to Re: how organize code in callback mode
by roboticus
in thread how organize code in callback mode
by xiaoyafeng
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |