An old-school way to do it is to:
- Initialize an array at the start of each row;
- Initialize a processing flag to false at the start of each row;
- Push each cell into that array as it is processed during the inner loop;
- Set the processing flag to true when you have your $patternmatch;
- At the bottom of the row loop, after processing all the cells in that row, if the flag is set, the array contains the complete row so use it accordingly.
my ( $row_min, $row_max ) = $worksheet->row_range();
my ( $col_min, $col_max ) = $worksheet->col_range();
for my $row ( $row_min .. $row_max ) {
my @rowcells = (); # Initialize array at start of new
+ row
my $process_flag = 0; # Initialize processing flag to fa
+lse
for my $col ( $col_min .. $col_max ) {
my $cell = $worksheet->get_cell( $row, $col );
if ($cell) {
push @rowcells, $cell; # Save cell in case we need it
if($cell->value eq $pattern)
{
$process_flag = 1; # We will need this line once it's
+ collected
}
} else {
push @rowcells, ''; # Assuming undef is not a useful o
+ption
}
if ($process_flag)
{
# Do something with @rowcells, which now contains the whole li
+ne
}
}